From 6d136a7e06d465ec4d100515d0971e18eae93e07 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 12 Jan 2024 09:53:51 +0100 Subject: [PATCH 1/8] [MDEPLOY-313] Update to parent 41, cleanup In general perform a cleanup of plugin, apply updates, where needed. The plugin now builds against latest 3.9.x and minimum is lifted to 3.6.3. --- https://issues.apache.org/jira/browse/MDEPLOY-313 --- pom.xml | 58 +++++++----- .../verify.groovy | 4 +- .../maven/plugins/deploy/DeployFileMojo.java | 27 ++---- .../plugins/deploy/DeployFileMojoTest.java | 16 ++-- .../maven/plugins/deploy/DeployMojoTest.java | 90 +++---------------- 5 files changed, 70 insertions(+), 125 deletions(-) diff --git a/pom.xml b/pom.xml index fc75b7c3..d831b1e8 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ under the License. org.apache.maven.plugins maven-plugins - 39 + 41 @@ -43,7 +43,7 @@ under the License. - ${mavenVersion} + 3.6.3 @@ -69,23 +69,23 @@ under the License. 8 - 3.2.5 + 3.9.6 - 1.7.5 + 1.7.36 - 1.0.0.v20140518 + 1.9.18 3.1.0 - 3.10.1 - 3.1.0 - 3.1.0 + 3.12.1 + 3.4.1 + 3.1.1 3.3.0 3.4.1 ${maven.plugin.tools.version} 3.3.0 3.2.1 - ${surefire.version} + 3.2.5 3.3.2 2023-03-21T14:38:01Z @@ -128,14 +128,18 @@ under the License. plexus-utils - org.eclipse.aether - aether-api + org.codehaus.plexus + plexus-xml + + + org.apache.maven.resolver + maven-resolver-api ${resolverVersion} provided - org.eclipse.aether - aether-util + org.apache.maven.resolver + maven-resolver-util ${resolverVersion} compile @@ -164,25 +168,25 @@ under the License. org.apache.maven - maven-aether-provider + maven-resolver-provider ${mavenVersion} test - org.eclipse.aether - aether-connector-basic + org.apache.maven.resolver + maven-resolver-connector-basic ${resolverVersion} test - org.eclipse.aether - aether-transport-file + org.apache.maven.resolver + maven-resolver-transport-file ${resolverVersion} test - org.eclipse.aether - aether-transport-http + org.apache.maven.resolver + maven-resolver-transport-http ${resolverVersion} test @@ -204,9 +208,21 @@ under the License. ${slf4jVersion} test - + + + + org.apache.maven.plugins + maven-compiler-plugin + + none + true + + + + + run-its diff --git a/src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy b/src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy index 2b197b2d..181104aa 100644 --- a/src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy +++ b/src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy @@ -25,5 +25,5 @@ File buildLog = new File( basedir, 'build.log' ) assert buildLog.exists() assert buildLog.text.contains( "[DEBUG] Using META-INF/maven/org.apache.maven.plugins.deploy.its/mdeploy178/pom.xml as pomFile" ) -def pomProject = new XmlSlurper().parse( deployedPom ) -assert "https://issues.apache.org/jira/browse/MDEPLOY-178".equals( pomProject.url.text() ) \ No newline at end of file +def pomProject = new groovy.xml.XmlParser().parse( deployedPom ) +assert "https://issues.apache.org/jira/browse/MDEPLOY-178".equals( pomProject.get("url").text() ) \ No newline at end of file diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java index aeaf5f77..7e6536f1 100644 --- a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java +++ b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java @@ -43,9 +43,9 @@ import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.WriterFactory; +import org.codehaus.plexus.util.xml.ReaderFactory; +import org.codehaus.plexus.util.xml.WriterFactory; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.artifact.Artifact; @@ -429,21 +429,14 @@ private void processModel(Model model) { * @throws MojoExecutionException If the file doesn't exist or cannot be read. */ Model readModel(File pomFile) throws MojoExecutionException { - Reader reader = null; - try { - reader = ReaderFactory.newXmlReader(pomFile); - final Model model = new MavenXpp3Reader().read(reader); - reader.close(); - reader = null; - return model; + try (Reader reader = ReaderFactory.newXmlReader(pomFile)) { + return new MavenXpp3Reader().read(reader); } catch (FileNotFoundException e) { throw new MojoExecutionException("POM not found " + pomFile, e); } catch (IOException e) { throw new MojoExecutionException("Error reading POM " + pomFile, e); } catch (XmlPullParserException e) { throw new MojoExecutionException("Error parsing POM " + pomFile, e); - } finally { - IOUtil.close(reader); } } @@ -456,23 +449,17 @@ Model readModel(File pomFile) throws MojoExecutionException { private File generatePomFile() throws MojoExecutionException { Model model = generateModel(); - Writer fw = null; try { File tempFile = File.createTempFile("mvndeploy", ".pom"); tempFile.deleteOnExit(); - fw = WriterFactory.newXmlWriter(tempFile); - - new MavenXpp3Writer().write(fw, model); - - fw.close(); - fw = null; + try (Writer fw = WriterFactory.newXmlWriter(tempFile)) { + new MavenXpp3Writer().write(fw, model); + } return tempFile; } catch (IOException e) { throw new MojoExecutionException("Error writing temporary pom file: " + e.getMessage(), e); - } finally { - IOUtil.close(fw); } } diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java index f36e6892..572d8e48 100644 --- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java @@ -28,6 +28,7 @@ import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.project.ProjectBuildingRequest; import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.internal.impl.DefaultLocalPathComposer; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; import org.mockito.InjectMocks; @@ -86,8 +87,9 @@ public void testBasicDeployFile() throws Exception { when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT); when(session.getProjectBuildingRequest()).thenReturn(buildingRequest); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); - repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory() - .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); + repositorySession.setLocalRepositoryManager( + new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer()) + .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); when(buildingRequest.getRepositorySession()).thenReturn(repositorySession); when(session.getRepositorySession()).thenReturn(repositorySession); @@ -194,8 +196,9 @@ public void testDeployIfClassifierIsSet() throws Exception { when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT); when(session.getProjectBuildingRequest()).thenReturn(buildingRequest); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); - repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory() - .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); + repositorySession.setLocalRepositoryManager( + new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer()) + .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); when(buildingRequest.getRepositorySession()).thenReturn(repositorySession); when(session.getRepositorySession()).thenReturn(repositorySession); @@ -248,8 +251,9 @@ public void testDeployIfArtifactIsNotJar() throws Exception { when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT); when(session.getProjectBuildingRequest()).thenReturn(buildingRequest); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); - repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory() - .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); + repositorySession.setLocalRepositoryManager( + new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer()) + .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); when(buildingRequest.getRepositorySession()).thenReturn(repositorySession); when(session.getRepositorySession()).thenReturn(repositorySession); diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java index c43bdf5c..fa2b7d5f 100644 --- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java @@ -23,7 +23,6 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import org.apache.maven.execution.MavenSession; @@ -37,11 +36,10 @@ import org.apache.maven.project.ProjectBuildingRequest; import org.codehaus.plexus.util.FileUtils; import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.internal.impl.DefaultLocalPathComposer; import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.RemoteRepository; -import org.junit.Ignore; import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; @@ -75,10 +73,11 @@ public void setUp() throws Exception { session = mock(MavenSession.class); when(session.getPluginContext(any(PluginDescriptor.class), any(MavenProject.class))) - .thenReturn(new ConcurrentHashMap()); + .thenReturn(new ConcurrentHashMap<>()); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); - repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory() - .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); + repositorySession.setLocalRepositoryManager( + new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer()) + .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); when(session.getRepositorySession()).thenReturn(repositorySession); remoteRepo = new File(REMOTE_REPO); @@ -124,8 +123,9 @@ public void testBasicDeploy() throws Exception { ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class); when(session.getProjectBuildingRequest()).thenReturn(buildingRequest); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); - repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory() - .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); + repositorySession.setLocalRepositoryManager( + new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer()) + .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); when(buildingRequest.getRepositorySession()).thenReturn(repositorySession); when(session.getRepositorySession()).thenReturn(repositorySession); @@ -300,8 +300,9 @@ public void testBasicDeployWithPackagingAsPom() throws Exception { ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class); when(session.getProjectBuildingRequest()).thenReturn(buildingRequest); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); - repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory() - .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); + repositorySession.setLocalRepositoryManager( + new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer()) + .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); when(buildingRequest.getRepositorySession()).thenReturn(repositorySession); when(session.getRepositorySession()).thenReturn(repositorySession); @@ -413,8 +414,9 @@ public void testDeployWithAttachedArtifacts() throws Exception { ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class); when(session.getProjectBuildingRequest()).thenReturn(buildingRequest); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); - repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory() - .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); + repositorySession.setLocalRepositoryManager( + new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer()) + .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); when(buildingRequest.getRepositorySession()).thenReturn(repositorySession); when(session.getRepositorySession()).thenReturn(repositorySession); @@ -490,70 +492,6 @@ public void testDeployWithAttachedArtifacts() throws Exception { assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles)); } - @Ignore("SCP is not part of Maven3 distribution. Aether handles transport extensions.") - public void _testBasicDeployWithScpAsProtocol() throws Exception { - String originalUserHome = System.getProperty("user.home"); - - // FIX THE DAMN user.home BEFORE YOU DELETE IT!!! - File altHome = new File(getBasedir(), "target/ssh-user-home"); - altHome.mkdirs(); - - System.out.println("Testing user.home value for .ssh dir: " + altHome.getCanonicalPath()); - - Properties props = System.getProperties(); - props.setProperty("user.home", altHome.getCanonicalPath()); - - System.setProperties(props); - - File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-scp/plugin-config.xml"); - - mojo = (DeployMojo) lookupMojo("deploy", testPom); - - assertNotNull(mojo); - - RepositorySystem repositorySystem = mock(RepositorySystem.class); - - setVariableValueToObject(mojo, "repositorySystem", repositorySystem); - - File file = new File( - getBasedir(), - "target/test-classes/unit/basic-deploy-scp/target/" + "deploy-test-file-1.0-SNAPSHOT.jar"); - - assertTrue(file.exists()); - - MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project"); - - setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>()); - setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project)); - - artifact = (DeployArtifactStub) project.getArtifact(); - - artifact.setFile(file); - - String altUserHome = System.getProperty("user.home"); - - if (altUserHome.equals(originalUserHome)) { - // this is *very* bad! - throw new IllegalStateException( - "Setting 'user.home' system property to alternate value did NOT work. Aborting test."); - } - - File sshFile = new File(altUserHome, ".ssh"); - - System.out.println("Testing .ssh dir: " + sshFile.getCanonicalPath()); - - // delete first the .ssh folder if existing before executing the mojo - if (sshFile.exists()) { - FileUtils.deleteDirectory(sshFile); - } - - mojo.execute(); - - assertTrue(sshFile.exists()); - - FileUtils.deleteDirectory(sshFile); - } - public void testLegacyAltDeploymentRepositoryWithDefaultLayout() throws Exception { DeployMojo mojo = new DeployMojo(); From 5353d54ef38eecd7ee482fafdce9e81e95e3d5b7 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 12 Jan 2024 11:40:25 +0100 Subject: [PATCH 2/8] Remove baked in packaging from plugin --- .../maven/plugins/deploy/DeployMojo.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java index c9b0d4a4..f8841b79 100644 --- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java +++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java @@ -38,8 +38,10 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.ProjectArtifact; +import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.deployment.DeployRequest; import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.util.artifact.ArtifactIdUtils; /** * Deploys an artifact to remote repository. @@ -285,17 +287,32 @@ private boolean hasExecution(Plugin plugin) { } private void processProject(final MavenProject project, DeployRequest request) throws MojoExecutionException { + // always exists, as project exists + Artifact pomArtifact = RepositoryUtils.toArtifact(new ProjectArtifact(project)); + // always exists, but at "init" is w/o file (packaging plugin assigns file to this when packaged) + Artifact projectArtifact = RepositoryUtils.toArtifact(project.getArtifact()); + + // pom project: pomArtifact and projectArtifact are SAME + // jar project: pomArtifact and projectArtifact are DIFFERENT + // incomplete project: is not pom project and projectArtifact has no file + + // we must compare coordinates ONLY (as projectArtifact may not have file, and Artifact.equals factors it in) + boolean pomArtifactIsMainArtifact = ArtifactIdUtils.equalsId(pomArtifact, projectArtifact); + if (pomArtifactIsMainArtifact) { + projectArtifact = null; + } + // is not packaged, is "incomplete" + boolean isIncomplete = projectArtifact != null && !isFile(projectArtifact.getFile()); - if (isFile(project.getFile())) { - request.addArtifact(RepositoryUtils.toArtifact(new ProjectArtifact(project))); + if (isFile(pomArtifact.getFile())) { + request.addArtifact(pomArtifact); } else { throw new MojoExecutionException("The project POM could not be attached"); } - if (!"pom".equals(project.getPackaging())) { - org.apache.maven.artifact.Artifact mavenMainArtifact = project.getArtifact(); - if (isFile(mavenMainArtifact.getFile())) { - request.addArtifact(RepositoryUtils.toArtifact(mavenMainArtifact)); + if (projectArtifact != null) { + if (!isIncomplete) { + request.addArtifact(projectArtifact); } else if (!project.getAttachedArtifacts().isEmpty()) { if (allowIncompleteProjects) { getLog().warn(""); From 889a2bcba28486daaa4f2173af7957ca3f388050 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 12 Jan 2024 11:42:42 +0100 Subject: [PATCH 3/8] Return original prerequisite --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d831b1e8..101b99a0 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ under the License. - 3.6.3 + 3.2.5 From 4ca3dc998563c7563027b6d04190e87baf520d76 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 12 Jan 2024 11:58:07 +0100 Subject: [PATCH 4/8] Add BOM UT --- .../maven/plugins/deploy/DeployMojoTest.java | 76 +++++++++++++++++++ .../deploy/stubs/DeployBomArtifactStub.java | 37 +++++++++ .../deploy/stubs/DeployPomArtifactStub.java | 37 +++++++++ .../unit/basic-deploy-bom/plugin-config.xml | 39 ++++++++++ .../unit/basic-deploy-pom/plugin-config.xml | 2 +- 5 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/apache/maven/plugins/deploy/stubs/DeployBomArtifactStub.java create mode 100644 src/test/java/org/apache/maven/plugins/deploy/stubs/DeployPomArtifactStub.java create mode 100644 src/test/resources/unit/basic-deploy-bom/plugin-config.xml diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java index fa2b7d5f..3b0df77e 100644 --- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java @@ -364,6 +364,82 @@ public void testBasicDeployWithPackagingAsPom() throws Exception { assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles)); } + public void testBasicDeployWithPackagingAsBom() throws Exception { + File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-bom/plugin-config.xml"); + + mojo = (DeployMojo) lookupMojo("deploy", testPom); + + MockitoAnnotations.initMocks(this); + + assertNotNull(mojo); + + ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class); + when(session.getProjectBuildingRequest()).thenReturn(buildingRequest); + DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); + repositorySession.setLocalRepositoryManager( + new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer()) + .newInstance(repositorySession, new LocalRepository(LOCAL_REPO))); + when(buildingRequest.getRepositorySession()).thenReturn(repositorySession); + when(session.getRepositorySession()).thenReturn(repositorySession); + + File pomFile = new File( + getBasedir(), + "target/test-classes/unit/basic-deploy-bom/target/" + "deploy-test-file-1.0-SNAPSHOT.pom"); + + assertTrue(pomFile.exists()); + + MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project"); + project.setGroupId("org.apache.maven.test"); + project.setArtifactId("maven-deploy-test"); + project.setVersion("1.0-SNAPSHOT"); + + setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>()); + setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project)); + + artifact = (DeployArtifactStub) project.getArtifact(); + + artifact.setArtifactHandlerExtension(project.getPackaging()); + + artifact.setFile(pomFile); + + ArtifactRepositoryStub repo = getRepoStub(mojo); + + repo.setAppendToUrl("basic-deploy-bom"); + + mojo.execute(); + + List expectedFiles = new ArrayList<>(); + List fileList = new ArrayList<>(); + + expectedFiles.add("org"); + expectedFiles.add("apache"); + expectedFiles.add("maven"); + expectedFiles.add("test"); + expectedFiles.add("maven-deploy-test"); + expectedFiles.add("1.0-SNAPSHOT"); + expectedFiles.add("maven-metadata.xml"); + expectedFiles.add("maven-metadata.xml.md5"); + expectedFiles.add("maven-metadata.xml.sha1"); + expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom"); + expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.md5"); + expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.sha1"); + // as we are in SNAPSHOT the file is here twice + expectedFiles.add("maven-metadata.xml"); + expectedFiles.add("maven-metadata.xml.md5"); + expectedFiles.add("maven-metadata.xml.sha1"); + remoteRepo = new File(remoteRepo, "basic-deploy-bom"); + + File[] files = remoteRepo.listFiles(); + + for (File file : Objects.requireNonNull(files)) { + addFileToList(file, fileList); + } + + assertEquals(expectedFiles.size(), fileList.size()); + + assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles)); + } + public void testDeployIfArtifactFileIsNull() throws Exception { File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml"); diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployBomArtifactStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployBomArtifactStub.java new file mode 100644 index 00000000..b5c55a37 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployBomArtifactStub.java @@ -0,0 +1,37 @@ +/* + * 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.deploy.stubs; + +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; + +public class DeployBomArtifactStub extends DeployArtifactStub { + @Override + public String getType() { + return "bom"; + } + + public ArtifactHandler getArtifactHandler() { + return new DefaultArtifactHandler() { + public String getExtension() { + return "pom"; + } + }; + } +} diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployPomArtifactStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployPomArtifactStub.java new file mode 100644 index 00000000..238bb286 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/DeployPomArtifactStub.java @@ -0,0 +1,37 @@ +/* + * 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.deploy.stubs; + +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; + +public class DeployPomArtifactStub extends DeployArtifactStub { + @Override + public String getType() { + return "pom"; + } + + public ArtifactHandler getArtifactHandler() { + return new DefaultArtifactHandler() { + public String getExtension() { + return "pom"; + } + }; + } +} diff --git a/src/test/resources/unit/basic-deploy-bom/plugin-config.xml b/src/test/resources/unit/basic-deploy-bom/plugin-config.xml new file mode 100644 index 00000000..9e41ab73 --- /dev/null +++ b/src/test/resources/unit/basic-deploy-bom/plugin-config.xml @@ -0,0 +1,39 @@ + + + + + + + maven-deploy-plugin + + + ${basedir}/src/test/resources/unit/basic-deploy-pom/plugin-config.xml + bom + + + + ${basedir} + + + + + + + diff --git a/src/test/resources/unit/basic-deploy-pom/plugin-config.xml b/src/test/resources/unit/basic-deploy-pom/plugin-config.xml index 8cf373c8..27d5f259 100644 --- a/src/test/resources/unit/basic-deploy-pom/plugin-config.xml +++ b/src/test/resources/unit/basic-deploy-pom/plugin-config.xml @@ -26,7 +26,7 @@ under the License. ${basedir}/src/test/resources/unit/basic-deploy-pom/plugin-config.xml pom - + ${basedir} From 7747d70e847a44b07d5049b6be3aa2676214ad21 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 12 Jan 2024 12:02:35 +0100 Subject: [PATCH 5/8] Add missing file --- .../target/deploy-test-file-1.0-SNAPSHOT.pom | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/resources/unit/basic-deploy-bom/target/deploy-test-file-1.0-SNAPSHOT.pom diff --git a/src/test/resources/unit/basic-deploy-bom/target/deploy-test-file-1.0-SNAPSHOT.pom b/src/test/resources/unit/basic-deploy-bom/target/deploy-test-file-1.0-SNAPSHOT.pom new file mode 100644 index 00000000..9c7bc402 --- /dev/null +++ b/src/test/resources/unit/basic-deploy-bom/target/deploy-test-file-1.0-SNAPSHOT.pom @@ -0,0 +1,28 @@ + + + + + 4.0.0 + org.apache.maven.test + maven-deploy-file-test + 1.0 + bom + + \ No newline at end of file From 23c116982eda70a123db29d49e8518fb1f604666 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 12 Jan 2024 12:11:24 +0100 Subject: [PATCH 6/8] Remove remnants of c+p --- src/test/resources/unit/basic-deploy-bom/plugin-config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/unit/basic-deploy-bom/plugin-config.xml b/src/test/resources/unit/basic-deploy-bom/plugin-config.xml index 9e41ab73..53bb8866 100644 --- a/src/test/resources/unit/basic-deploy-bom/plugin-config.xml +++ b/src/test/resources/unit/basic-deploy-bom/plugin-config.xml @@ -24,7 +24,7 @@ under the License. maven-deploy-plugin - ${basedir}/src/test/resources/unit/basic-deploy-pom/plugin-config.xml + ${basedir}/src/test/resources/unit/basic-deploy-bom/plugin-config.xml bom From 28fef5792c3ad33b202b8350dbcf2c030a8d486a Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 12 Jan 2024 12:22:02 +0100 Subject: [PATCH 7/8] Last nit If pom A and project A has same coordinates, BUT the project A has file set, use that instead. --- .../org/apache/maven/plugins/deploy/DeployMojo.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java index f8841b79..c3ea850a 100644 --- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java +++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java @@ -297,12 +297,13 @@ private void processProject(final MavenProject project, DeployRequest request) t // incomplete project: is not pom project and projectArtifact has no file // we must compare coordinates ONLY (as projectArtifact may not have file, and Artifact.equals factors it in) - boolean pomArtifactIsMainArtifact = ArtifactIdUtils.equalsId(pomArtifact, projectArtifact); - if (pomArtifactIsMainArtifact) { + // BUT if projectArtifact has file set, use that one + if (ArtifactIdUtils.equalsId(pomArtifact, projectArtifact)) { + if (isFile(projectArtifact.getFile())) { + pomArtifact = projectArtifact; + } projectArtifact = null; } - // is not packaged, is "incomplete" - boolean isIncomplete = projectArtifact != null && !isFile(projectArtifact.getFile()); if (isFile(pomArtifact.getFile())) { request.addArtifact(pomArtifact); @@ -310,6 +311,8 @@ private void processProject(final MavenProject project, DeployRequest request) t throw new MojoExecutionException("The project POM could not be attached"); } + // is not packaged, is "incomplete" + boolean isIncomplete = projectArtifact != null && !isFile(projectArtifact.getFile()); if (projectArtifact != null) { if (!isIncomplete) { request.addArtifact(projectArtifact); From ff8c70c6a8dd6efb2dbf1d95bf715fb794d4522f Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 12 Jan 2024 12:34:01 +0100 Subject: [PATCH 8/8] Use version properties from parent --- pom.xml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 101b99a0..0340c384 100644 --- a/pom.xml +++ b/pom.xml @@ -76,17 +76,17 @@ under the License. 1.9.18 - 3.1.0 - 3.12.1 - 3.4.1 - 3.1.1 - 3.3.0 - 3.4.1 - ${maven.plugin.tools.version} - 3.3.0 - 3.2.1 - 3.2.5 - 3.3.2 + ${version.maven-antrun-plugin} + ${version.maven-compiler-plugin} + ${version.maven-enforcer-plugin} + ${version.maven-install-plugin} + ${version.maven-jar-plugin} + ${version.maven-javadoc-plugin} + ${version.maven-plugin-tools} + ${version.maven-resources-plugin} + ${version.maven-source-plugin} + ${version.maven-surefire} + ${version.maven-war-plugin} 2023-03-21T14:38:01Z