diff --git a/.asf.yaml b/.asf.yaml index 699735c5..d4bb4049 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -13,4 +13,9 @@ github: merge: false rebase: true autolink_jira: - - MDEPLOY \ No newline at end of file + - MDEPLOY +notifications: + commits: commits@maven.apache.org + issues: issues@maven.apache.org + pullrequests: issues@maven.apache.org + jira_options: link label comment diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..778ea2af --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,27 @@ +# 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. + +version: 2 +updates: + - package-ecosystem: "maven" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/maven-verify.yml b/.github/workflows/maven-verify.yml index 4d67fdcf..cd3c4512 100644 --- a/.github/workflows/maven-verify.yml +++ b/.github/workflows/maven-verify.yml @@ -24,4 +24,5 @@ on: jobs: build: name: Verify - uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v3 + uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v4 + diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index b44872cf..1049eaa3 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -22,4 +22,4 @@ on: - master jobs: update_release_draft: - uses: apache/maven-gh-actions-shared/.github/workflows/release-drafter.yml@v3 + uses: apache/maven-gh-actions-shared/.github/workflows/release-drafter.yml@v4 diff --git a/pom.xml b/pom.xml index 96df086c..a4363e37 100644 --- a/pom.xml +++ b/pom.xml @@ -23,12 +23,12 @@ under the License. org.apache.maven.plugins maven-plugins - 39 + 42 maven-deploy-plugin - 3.1.1 + 3.1.2 maven-plugin Apache Maven Deploy Plugin @@ -43,13 +43,13 @@ under the License. - ${mavenVersion} + 3.6.3 scm:git:https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git scm:git:https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git - maven-deploy-plugin-3.1.1 + maven-deploy-plugin-3.1.2 https://github.com/apache/maven-deploy-plugin/tree/${project.scm.tag} @@ -69,26 +69,26 @@ 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.3.0 - 3.4.1 - ${maven.plugin.tools.version} - 3.3.0 - 3.2.1 - ${surefire.version} - 3.3.2 - - 2023-03-21T14:37:32Z + ${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} + + 2024-04-26T10:30:22Z @@ -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,32 +168,32 @@ 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 org.mockito mockito-core - 2.28.2 + 4.11.0 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/AbstractDeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java index 2c5c1d9c..d8da6922 100644 --- a/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java +++ b/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java @@ -99,6 +99,7 @@ protected void warnIfAffectedPackagingAndMaven(final String packaging) { * Creates resolver {@link RemoteRepository} equipped with needed whistles and bells. */ protected RemoteRepository getRemoteRepository(final String repositoryId, final String url) { + // TODO: RepositorySystem#newDeploymentRepository does this very same thing! RemoteRepository result = new RemoteRepository.Builder(repositoryId, "default", url).build(); if (result.getAuthentication() == null || result.getProxy() == null) { 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 c6c875b1..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; @@ -269,7 +269,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { ArtifactType artifactType = session.getRepositorySession().getArtifactTypeRegistry().get(packaging); if (artifactType != null - && StringUtils.isEmpty(classifier) + && (classifier == null || classifier.isEmpty()) && !StringUtils.isEmpty(artifactType.getClassifier())) { classifier = artifactType.getClassifier(); } @@ -426,24 +426,17 @@ private void processModel(Model model) { * * @param pomFile The path of the POM file to parse, must not be null. * @return The model from the POM file, never null. - * @throws MojoExecutionException If the file doesn't exist of cannot be read. + * @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/main/java/org/apache/maven/plugins/deploy/DeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java index c9b0d4a4..79ee1d87 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,32 +287,52 @@ 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) + // BUT if projectArtifact has file set, use that one + if (ArtifactIdUtils.equalsId(pomArtifact, projectArtifact)) { + if (isFile(projectArtifact.getFile())) { + pomArtifact = projectArtifact; + } + projectArtifact = null; + } - 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"); + throw new MojoExecutionException( + "The POM for project " + project.getArtifactId() + " 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)); + // is not packaged, is "incomplete" + boolean isIncomplete = projectArtifact != null && !isFile(projectArtifact.getFile()); + if (projectArtifact != null) { + if (!isIncomplete) { + request.addArtifact(projectArtifact); } else if (!project.getAttachedArtifacts().isEmpty()) { if (allowIncompleteProjects) { getLog().warn(""); - getLog().warn("The packaging plugin for this project did not assign"); + getLog().warn("The packaging plugin for project " + project.getArtifactId() + " did not assign"); getLog().warn("a main file to the project but it has attachments. Change packaging to 'pom'."); getLog().warn(""); getLog().warn("Incomplete projects like this will fail in future Maven versions!"); getLog().warn(""); } else { - throw new MojoExecutionException("The packaging plugin for this project did not assign " - + "a main file to the project but it has attachments. Change packaging to 'pom'."); + throw new MojoExecutionException("The packaging plugin for project " + project.getArtifactId() + + " did not assign a main file to the project but it has attachments. Change packaging" + + " to 'pom'."); } } else { - throw new MojoExecutionException( - "The packaging for this project did not assign a file to the build artifact"); + throw new MojoExecutionException("The packaging plugin for project " + project.getArtifactId() + + " did not assign a file to the build artifact"); } } diff --git a/src/site/apt/index.apt.vm b/src/site/apt/index.apt.vm index 262e90a1..1ad2e42a 100644 --- a/src/site/apt/index.apt.vm +++ b/src/site/apt/index.apt.vm @@ -85,7 +85,7 @@ ${project.name} already contain the answer to your question as part of an older thread. Hence, it is also worth browsing/searching the {{{./mailing-lists.html}mail archive}}. - If you feel like the plugin is missing a feature or has a defect, you can fill a feature request or bug report in our + If you feel like the plugin is missing a feature or has a defect, you can file a feature request or bug report in our {{{./issue-management.html}issue tracker}}. When creating a new issue, please provide a comprehensive description of your concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated. 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..5884ae11 100644 --- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java @@ -38,6 +38,7 @@ 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; @@ -75,10 +76,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 +126,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 +303,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); @@ -363,6 +367,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"); @@ -393,10 +473,46 @@ public void testDeployIfArtifactFileIsNull() throws Exception { try { mojo.execute(); + fail("Did not throw mojo execution exception"); + } catch (MojoExecutionException e) { + // expected, message should include artifactId + assertEquals( + "The packaging plugin for project maven-deploy-test did not assign a file to the build artifact", + e.getMessage()); + } + } + + public void testDeployIfProjectFileIsNull() throws Exception { + File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml"); + + DeployMojo mojo = (DeployMojo) lookupMojo("deploy", testPom); + + MockitoAnnotations.initMocks(this); + + ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class); + when(session.getProjectBuildingRequest()).thenReturn(buildingRequest); + + setVariableValueToObject(mojo, "session", session); + + assertNotNull(mojo); + + MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project"); + project.setGroupId("org.apache.maven.test"); + project.setArtifactId("maven-deploy-test"); + project.setVersion("1.0-SNAPSHOT"); + + project.setFile(null); + assertNull(project.getFile()); + setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>()); + setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project)); + + try { + mojo.execute(); fail("Did not throw mojo execution exception"); } catch (MojoExecutionException e) { - // expected + // expected, message should include artifactId + assertEquals("The POM for project maven-deploy-test could not be attached", e.getMessage()); } } @@ -413,8 +529,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,6 +607,42 @@ public void testDeployWithAttachedArtifacts() throws Exception { assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles)); } + public void testNonPomDeployWithAttachedArtifactsOnly() throws Exception { + File testPom = new File( + getBasedir(), "target/test-classes/unit/basic-deploy-with-attached-artifacts/" + "plugin-config.xml"); + + mojo = (DeployMojo) lookupMojo("deploy", testPom); + + MockitoAnnotations.initMocks(this); + + assertNotNull(mojo); + + ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class); + when(session.getProjectBuildingRequest()).thenReturn(buildingRequest); + + 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.setFile(null); + + try { + mojo.execute(); + fail("Did not throw mojo execution exception"); + } catch (MojoExecutionException e) { + // expected, message should include artifactId + assertEquals( + "The packaging plugin for project maven-deploy-test did not assign a main file to the project " + + "but it has attachments. Change packaging to 'pom'.", + e.getMessage()); + } + } + @Ignore("SCP is not part of Maven3 distribution. Aether handles transport extensions.") public void _testBasicDeployWithScpAsProtocol() throws Exception { String originalUserHome = System.getProperty("user.home"); 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..53bb8866 --- /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-bom/plugin-config.xml + bom + + + + ${basedir} + + + + + + + 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 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}