Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.inject.Inject;

import java.io.File;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -112,10 +113,13 @@ public void execute() throws MojoExecutionException {
Set<Artifact> artifacts = project.getArtifacts();

for (Artifact artifact : artifacts) {
project.getProperties()
.setProperty(
artifact.getDependencyConflictId(),
artifact.getFile().getAbsolutePath());
String conflictId = artifact.getDependencyConflictId();
File file = artifact.getFile();
if (file == null) {
getLog().warn("Artifact " + conflictId + " has no associated file; no property will be set for it.");
continue;
}
project.getProperties().setProperty(conflictId, file.getAbsolutePath());
}

if (extraArtifacts != null) {
Expand All @@ -130,10 +134,14 @@ public void execute() throws MojoExecutionException {
resolverUtil.createArtifactFromParams(paramArtifact);
artifact = resolverUtil.resolveArtifact(artifact, project.getRemoteProjectRepositories());

this.project
.getProperties()
.setProperty(
toConflictId(artifact), artifact.getFile().getAbsolutePath());
String conflictId = toConflictId(artifact);
File file = artifact.getFile();
if (file == null) {
getLog().warn("Extra artifact " + conflictId
+ " has no associated file; no property will be set for it.");
continue;
}
this.project.getProperties().setProperty(conflictId, file.getAbsolutePath());
}
} catch (ArtifactResolutionException | ArtifactDescriptorException e) {
throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -102,4 +103,17 @@ void testSetPropertiesForExtractArtifacts(PropertiesMojo mojo) throws Exception
assertTrue(project.getProperties().containsKey(depId2));
assertTrue(new File(project.getProperties().getProperty(depId1)).exists());
}

@Test
@InjectMojo(goal = "properties")
void testNullFileSkipsProperty(PropertiesMojo mojo) throws Exception {
Artifact artifact = Mockito.mock(Artifact.class);
when(artifact.getDependencyConflictId()).thenReturn("group:artifact");
when(artifact.getFile()).thenReturn(null);
when(this.project.getArtifacts()).thenReturn(new HashSet<>(Arrays.asList(artifact)));

mojo.execute();

assertFalse(project.getProperties().containsKey("group:artifact"));
}
}
Loading