This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch maven-install-plugin-4.x in repository https://gitbox.apache.org/repos/asf/maven-install-plugin.git
commit 606f966a368cf73b0a0a6887fd40fabfecceefa4 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Sat Nov 21 14:35:10 2026 +0100 Extract shared checksum assertion helper and narrow model-read exception catch Addresses review comments on #499 --- .../maven/plugins/install/InstallFileMojoTest.java | 26 ++++---------- .../install/InstallMojoPomPackagingTest.java | 19 +--------- .../maven/plugins/install/InstallMojoTest.java | 17 +-------- .../maven/plugins/install/InstallTestHelper.java | 41 ++++++++++++++++++++++ 4 files changed, 49 insertions(+), 54 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java index 03c1a2b..321df52 100644 --- a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java @@ -31,7 +31,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; -import java.util.stream.Stream; import org.apache.maven.api.Artifact; import org.apache.maven.api.LocalRepository; @@ -52,6 +51,7 @@ import org.apache.maven.api.services.ArtifactInstaller; import org.apache.maven.api.services.ArtifactInstallerRequest; import org.apache.maven.api.services.ArtifactManager; import org.apache.maven.api.services.xml.ModelXmlFactory; +import org.apache.maven.api.services.xml.XmlReaderException; import org.apache.maven.testing.plugin.stubs.ArtifactStub; import org.codehaus.plexus.util.FileUtils; import org.junit.jupiter.api.BeforeEach; @@ -696,7 +696,7 @@ class InstallFileMojoTest { assertEquals(groupId, model.get().getGroupId()); assertEquals(artifactId, model.get().getArtifactId()); assertEquals(version, model.get().getVersion()); - assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO)); + InstallTestHelper.assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO)); } /** Converted from {@code src/it/generate-pom-auto-2}: a POM already in the repo is never overwritten. */ @@ -725,7 +725,7 @@ class InstallFileMojoTest { 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)); + InstallTestHelper.assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO)); } /** Converted from {@code src/it/local-repo-override-with-checksum}: install into a custom local repository. */ @@ -754,7 +754,7 @@ class InstallFileMojoTest { assertEquals( Paths.get(getBasedir(), OVERRIDE_REPO).toString().replace(File.separator, "/"), request.getSession().getLocalRepository().getPath().toString().replace(File.separator, "/")); - assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO)); + InstallTestHelper.assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO)); } /** @@ -791,7 +791,7 @@ class InstallFileMojoTest { assertEquals(groupId, model.get().getGroupId()); assertEquals(artifactId, model.get().getArtifactId()); assertEquals(version, model.get().getVersion()); - assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO)); + InstallTestHelper.assertNoChecksumFiles(Paths.get(getBasedir(), OVERRIDE_REPO)); } private void assertFileExistsInRequest(ArtifactInstallerRequest request, Artifact artifact) { @@ -805,7 +805,7 @@ class InstallFileMojoTest { Path pomPath = requestArtifactManager.getPath(pom).orElse(null); assertNotNull(pomPath); return session.getService(ModelXmlFactory.class).read(pomPath); - } catch (Exception e) { + } catch (XmlReaderException e) { throw new IllegalStateException(e); } } @@ -823,20 +823,6 @@ class InstallFileMojoTest { return e; } - private static void assertNoChecksumFiles(Path repositoryRoot) throws Exception { - if (!Files.exists(repositoryRoot)) { - return; - } - try (Stream<Path> paths = Files.walk(repositoryRoot)) { - assertTrue( - paths.noneMatch(p -> { - String name = p.getFileName().toString(); - return name.endsWith(".md5") || name.endsWith(".sha1"); - }), - "no .md5/.sha1 checksum files should be created"); - } - } - private static Path createJarWithEntries(String pomContent, String... entryNames) throws Exception { Path jar = Files.createTempFile("maven-install-file-test", ".jar"); try (JarOutputStream jos = new JarOutputStream(Files.newOutputStream(jar))) { diff --git a/src/test/java/org/apache/maven/plugins/install/InstallMojoPomPackagingTest.java b/src/test/java/org/apache/maven/plugins/install/InstallMojoPomPackagingTest.java index a2a5555..a59315a 100644 --- a/src/test/java/org/apache/maven/plugins/install/InstallMojoPomPackagingTest.java +++ b/src/test/java/org/apache/maven/plugins/install/InstallMojoPomPackagingTest.java @@ -19,14 +19,11 @@ package org.apache.maven.plugins.install; import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collection; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; -import java.util.stream.Stream; import org.apache.maven.api.Artifact; import org.apache.maven.api.MojoExecution; @@ -124,21 +121,7 @@ class InstallMojoPomPackagingTest { 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 { - if (!Files.exists(repositoryRoot)) { - return; - } - try (Stream<Path> paths = Files.walk(repositoryRoot)) { - assertTrue( - paths.noneMatch(p -> { - String name = p.getFileName().toString(); - return name.endsWith(".md5") || name.endsWith(".sha1"); - }), - "no .md5/.sha1 checksum files should be created"); - } + InstallTestHelper.assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO)); } @Provides diff --git a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java index dfe6b4e..33c1d5b 100644 --- a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java @@ -31,7 +31,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Stream; import org.apache.maven.api.Artifact; import org.apache.maven.api.MojoExecution; @@ -344,7 +343,7 @@ class InstallMojoTest { 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)); + InstallTestHelper.assertNoChecksumFiles(Paths.get(getBasedir(), LOCAL_REPO)); } private void attachClassifiedJar(Project project, String classifier) { @@ -355,20 +354,6 @@ class InstallMojoTest { Paths.get(getBasedir()).resolve(ATTACHED_ARTIFACT_JAR)); } - private static void assertNoChecksumFiles(Path repositoryRoot) throws Exception { - if (!Files.exists(repositoryRoot)) { - return; - } - try (Stream<Path> paths = Files.walk(repositoryRoot)) { - assertTrue( - paths.noneMatch(p -> { - String name = p.getFileName().toString(); - return name.endsWith(".md5") || name.endsWith(".sha1"); - }), - "no .md5/.sha1 checksum files should be created"); - } - } - private Project reactorProject(String artifactId) { Project project = mock(Project.class); when(project.getBuild()).thenReturn(installPluginBuild("default-install", "install")); diff --git a/src/test/java/org/apache/maven/plugins/install/InstallTestHelper.java b/src/test/java/org/apache/maven/plugins/install/InstallTestHelper.java new file mode 100644 index 0000000..55cfa57 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/install/InstallTestHelper.java @@ -0,0 +1,41 @@ +/* + * 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.plugins.install; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +class InstallTestHelper { + static void assertNoChecksumFiles(Path repositoryRoot) throws Exception { + if (!Files.exists(repositoryRoot)) { + return; + } + try (Stream<Path> paths = Files.walk(repositoryRoot)) { + assertTrue( + paths.noneMatch(p -> { + String name = p.getFileName().toString(); + return name.endsWith(".md5") || name.endsWith(".sha1"); + }), + "no .md5/.sha1 checksum files should be created"); + } + } +}
