slachiewicz commented on code in PR #499:
URL: 
https://github.com/apache/maven-install-plugin/pull/499#discussion_r4652751073


##########
src/test/java/org/apache/maven/plugins/install/InstallMojoPomPackagingTest.java:
##########
@@ -103,6 +107,40 @@ void installIfPackagingIsPom(InstallMojo mojo) throws 
Exception {
                 artifacts.stream().map(Artifact::key).toList());
     }
 
+    /** Converted from {@code src/it/pom-checksum}: the POM is installed and 
no checksum files are created. */
+    @Test
+    @InjectMojo(goal = "install")
+    @MojoParameter(name = "installAtEnd", value = "false")
+    void pomPackagingInstalledWithoutChecksums(InstallMojo mojo) throws 
Exception {
+        assertNotNull(mojo);
+        Project project = (Project) getVariableValueFromObject(mojo, 
"project");
+        artifactManager.setPath(project.getPomArtifact(), 
project.getPomPath());
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        assertEquals(
+                
List.of("org.apache.maven.test:maven-install-test:pom:1.0-SNAPSHOT"),
+                request.getArtifacts().stream().map(Artifact::key).toList());
+        assertTrue(request.getArtifacts().stream()
+                .noneMatch(a -> "md5".equals(a.getExtension()) || 
"sha1".equals(a.getExtension())));
+        assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO));
+    }
+
+    private static void assertNoChecksumFiles(Path repositoryRoot) throws 
Exception {

Review Comment:
   Done. Extracted the identical helper into a package-private 
`InstallTestHelper.assertNoChecksumFiles(Path)` and switched all three test 
classes to it. No behaviour change: 45/45 unit tests pass, spotless and 
checkstyle clean.



##########
src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java:
##########
@@ -619,6 +623,220 @@ void dotDotVersionRejected(InstallFileMojo mojo) {
         assertTrue(e.getMessage().contains("not valid"), e.getMessage());
     }
 
+    // 
-------------------------------------------------------------------------------------------------------
+    // Conversions of the src/it integration tests that only exercised 
install:install-file mojo behaviour.
+    // The real ArtifactInstaller is mocked by the harness, so "installed" is 
asserted as the set of
+    // artifacts handed to it (plus the generated POM model captured while the 
install call is in flight).
+    // Checksum files are produced by Maven's ArtifactInstaller, never by this 
mojo; at this level we
+    // assert that no checksum artifact is handed to the installer and that 
none is left in the repo.
+    // 
-------------------------------------------------------------------------------------------------------
+
+    /** Converted from {@code src/it/gav-validation} (invalid coordinates, 
test-invalid.properties). */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "invalid~group")
+    @MojoParameter(name = "artifactId", value = "invalid/artifactId")
+    @MojoParameter(name = "version", value = "1+")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void invalidGavRejectedAndNothingInstalled(InstallFileMojo mojo) {
+        assertNotNull(mojo);
+
+        MojoException e = executeExpectingFailure(mojo);
+
+        assertTrue(e.getMessage().contains("The artifact information is not 
valid"), e.getMessage());
+    }
+
+    /** Converted from {@code src/it/gav-validation} (missing coordinates, 
test-missing.properties). */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "groupId")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void missingCoordinatesRejectedAndNothingInstalled(InstallFileMojo mojo) 
throws Exception {
+        assertNotNull(mojo);
+        // A jar with no embedded POM keeps the coordinates genuinely 
incomplete.
+        Path plainJar = createJarWithEntryBytes(
+                "Manifest-Version: 1.0\n".getBytes(StandardCharsets.UTF_8), 
"META-INF/MANIFEST.MF");
+        setVariableValueToObject(mojo, "file", plainJar);
+
+        MojoException e = executeExpectingFailure(mojo);
+
+        assertTrue(e.getMessage().contains("The artifact information is 
incomplete"), e.getMessage());
+    }
+
+    /** Converted from {@code src/it/generate-pom-auto-1}: with the default 
generatePom, a jar and a POM are installed. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = 
"org.apache.maven.its.install.gpa1")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void generatePomAutoInstallsJarAndPom(InstallFileMojo mojo) throws 
Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        AtomicReference<Model> model = new AtomicReference<>();
+        ArtifactInstallerRequest request =
+                execute(mojo, air -> model.set(readModelFrom(air, 
getArtifact(null, "pom"))));
+
+        assertNotNull(request);
+        Artifact pom = getArtifact(null, "pom");
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(new HashSet<>(Arrays.asList(pom, jar)), new 
HashSet<>(request.getArtifacts()));
+        assertFileExists(artifactManager.getPath(jar).orElse(null));
+        assertEquals("4.0.0", model.get().getModelVersion());
+        assertEquals(groupId, model.get().getGroupId());
+        assertEquals(artifactId, model.get().getArtifactId());
+        assertEquals(version, model.get().getVersion());
+        assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO));
+    }
+
+    /** Converted from {@code src/it/generate-pom-auto-2}: a POM already in 
the repo is never overwritten. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = 
"org.apache.maven.its.install.gpa2")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    void existingPomNotOverwrittenWhenGeneratePomAuto(InstallFileMojo mojo) 
throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        Path existingPom =
+                Paths.get(getBasedir(), LOCAL_REPO, 
"org/apache/maven/its/install/gpa2/test/0.1/test-0.1.pom");
+        Files.createDirectories(existingPom.getParent());
+        Files.writeString(existingPom, "test");
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(Collections.singleton(jar), new 
HashSet<>(request.getArtifacts()));
+        assertFileExists(artifactManager.getPath(jar).orElse(null));
+        assertEquals("test", Files.readString(existingPom), "existing POM must 
keep its original 4-byte content");
+        assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO));
+    }
+
+    /** Converted from {@code src/it/local-repo-override-with-checksum}: 
install into a custom local repository. */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "gid")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    @MojoParameter(name = "localRepositoryPath", value = 
"target/local-repo-override")
+    void installFileIntoOverriddenLocalRepositoryNoChecksums(InstallFileMojo 
mojo) throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        ArtifactInstallerRequest request = execute(mojo);
+
+        assertNotNull(request);
+        Artifact jar = getArtifact(null, "jar");
+        assertTrue(request.getArtifacts().contains(jar), "the jar must be 
installed into the overridden repository");
+        assertTrue(request.getArtifacts().stream()
+                .noneMatch(a -> "md5".equals(a.getExtension()) || 
"sha1".equals(a.getExtension())));
+        assertFileExistsInRequest(request, jar);
+        assertEquals(
+                Paths.get(getBasedir(), 
OVERRIDE_REPO).toString().replace(File.separator, "/"),
+                
request.getSession().getLocalRepository().getPath().toString().replace(File.separator,
 "/"));
+        assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO));
+    }
+
+    /**
+     * Converted from {@code 
src/it/local-repo-override-with-checksum-generatePom}: the generated POM is 
installed
+     * into the custom local repository too, and neither jar nor POM gets a 
checksum file.
+     */
+    @Test
+    @InjectMojo(goal = "install-file")
+    @MojoParameter(name = "groupId", value = "gid")
+    @MojoParameter(name = "artifactId", value = "test")
+    @MojoParameter(name = "version", value = "0.1")
+    @MojoParameter(name = "packaging", value = "jar")
+    @MojoParameter(
+            name = "file",
+            value = 
"${project.basedir}/target/test-classes/unit/maven-install-test-1.0-SNAPSHOT.jar")
+    @MojoParameter(name = "generatePom", value = "true")
+    @MojoParameter(name = "localRepositoryPath", value = 
"target/local-repo-override")
+    void 
installFileIntoOverriddenLocalRepositoryWithGeneratedPomNoChecksums(InstallFileMojo
 mojo) throws Exception {
+        assertNotNull(mojo);
+        assignValuesForParameter(mojo);
+
+        AtomicReference<Model> model = new AtomicReference<>();
+        ArtifactInstallerRequest request =
+                execute(mojo, air -> model.set(readModelFrom(air, 
getArtifact(null, "pom"))));
+
+        assertNotNull(request);
+        Artifact pom = getArtifact(null, "pom");
+        Artifact jar = getArtifact(null, "jar");
+        assertEquals(new HashSet<>(Arrays.asList(pom, jar)), new 
HashSet<>(request.getArtifacts()));
+        assertFileExistsInRequest(request, jar);
+        assertEquals(
+                Paths.get(getBasedir(), 
OVERRIDE_REPO).toString().replace(File.separator, "/"),
+                
request.getSession().getLocalRepository().getPath().toString().replace(File.separator,
 "/"));
+        assertEquals(groupId, model.get().getGroupId());
+        assertEquals(artifactId, model.get().getArtifactId());
+        assertEquals(version, model.get().getVersion());
+        assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO));
+    }
+
+    private void assertFileExistsInRequest(ArtifactInstallerRequest request, 
Artifact artifact) {
+        ArtifactManager requestArtifactManager = 
request.getSession().getService(ArtifactManager.class);
+        
assertFileExists(requestArtifactManager.getPath(artifact).orElse(null));
+    }
+
+    private Model readModelFrom(ArtifactInstallerRequest request, Artifact 
pom) {
+        try {
+            ArtifactManager requestArtifactManager = 
request.getSession().getService(ArtifactManager.class);
+            Path pomPath = requestArtifactManager.getPath(pom).orElse(null);
+            assertNotNull(pomPath);
+            return session.getService(ModelXmlFactory.class).read(pomPath);
+        } catch (Exception e) {

Review Comment:
   Done. Narrowed to `catch (XmlReaderException e)` and added the import, so 
unexpected IO/runtime failures propagate instead of being wrapped. 45/45 unit 
tests still pass.



-- 
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