Skip to content

Commit

Permalink
Check if artifact exits before attach it to not get warned by maven
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
laeubi committed Dec 4, 2023
1 parent d18b5f1 commit 2c27d42
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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())) {
Expand Down

0 comments on commit 2c27d42

Please sign in to comment.