From f6ef54cd98a0b60809dda034f7ba31a670b3d9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 4 Dec 2023 12:57:15 +0100 Subject: [PATCH] Check if artifact exits before attach it to not get warned by maven MavenProjectHelper claims it can replace artifacts but this generates a warning for the user, to prevent this we now check for an already attached artifact and simply update the file (even though it should already point to the right one). (cherry picked from commit 2c27d427f7714ea27857fbed3638ad30dd0e4e1c) --- .../tycho/plugins/p2/P2MetadataMojo.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/P2MetadataMojo.java b/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/P2MetadataMojo.java index e8db5ebb87..68a9e91382 100644 --- a/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/P2MetadataMojo.java +++ b/tycho-p2-plugin/src/main/java/org/eclipse/tycho/plugins/p2/P2MetadataMojo.java @@ -202,10 +202,10 @@ protected void attachP2Metadata() throws MojoExecutionException { File contentsXml = new File(targetDir, TychoConstants.FILE_NAME_P2_METADATA); File artifactsXml = new File(targetDir, TychoConstants.FILE_NAME_P2_ARTIFACTS); p2generator.persistMetadata(generatedMetadata, contentsXml, artifactsXml); - projectHelper.attachArtifact(project, TychoConstants.EXTENSION_P2_METADATA, - TychoConstants.CLASSIFIER_P2_METADATA, contentsXml); - projectHelper.attachArtifact(project, TychoConstants.EXTENSION_P2_ARTIFACTS, - TychoConstants.CLASSIFIER_P2_ARTIFACTS, artifactsXml); + attachArtifact(project, TychoConstants.EXTENSION_P2_METADATA, TychoConstants.CLASSIFIER_P2_METADATA, + contentsXml); + attachArtifact(project, TychoConstants.EXTENSION_P2_ARTIFACTS, TychoConstants.CLASSIFIER_P2_ARTIFACTS, + artifactsXml); ReactorProject reactorProject = DefaultReactorProject.adapt(project); @@ -231,6 +231,21 @@ protected void attachP2Metadata() throws MojoExecutionException { writeArtifactLocations(localArtifactsFile, getAllProjectArtifacts(project)); } + /** + * Performs an add or replace of the specified artifact, even though javadoc of + * {@link MavenProjectHelper} claims it can replace artifacts that generates a warning in recent + * maven versions. + */ + private void attachArtifact(MavenProject project, String type, String classifier, File file) { + for (Artifact artifact : project.getAttachedArtifacts()) { + if (classifier.equals(artifact.getClassifier()) && type.equals(artifact.getType())) { + artifact.setFile(file); + return; + } + } + projectHelper.attachArtifact(project, type, classifier, file); + } + private static boolean hasAttachedArtifact(MavenProject project, String classifier) { for (Artifact artifact : project.getAttachedArtifacts()) { if (classifier.equals(artifact.getClassifier())) {