Skip to content

Commit

Permalink
NPE in MirrorMojo when using target platform as source
Browse files Browse the repository at this point in the history
Source is allowed to be unset when sourcing bundles from the target
platform (i.e. when targetPlatformAsSource is set) so just add a
null check and continue.

Signed-off-by: Mat Booth <mat.booth@gmail.com>
  • Loading branch information
mbooth101 authored and laeubi committed Feb 15, 2022
1 parent 89ef155 commit 2e89f62
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
} else {
sourceDescriptor = new RepositoryReferences();
}
for (final Repository sourceRepository : source) {
if (sourceRepository.getLayout().hasMetadata()) {
sourceDescriptor.addMetadataRepository(sourceRepository.getLocation());
}
if (sourceRepository.getLayout().hasArtifacts()) {
sourceDescriptor.addArtifactRepository(sourceRepository.getLocation());
if (source != null) {
for (final Repository sourceRepository : source) {
if (sourceRepository.getLayout().hasMetadata()) {
sourceDescriptor.addMetadataRepository(sourceRepository.getLocation());
}
if (sourceRepository.getLayout().hasArtifacts()) {
sourceDescriptor.addArtifactRepository(sourceRepository.getLocation());
}
}
}
if (sourceDescriptor.getArtifactRepositories().isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.shared.utils.io.FileUtils;
Expand Down Expand Up @@ -117,6 +118,21 @@ public void testMirrorWithPlatformFilter() throws Exception {
assertMirroredBundle(mirrorDestinationDir, "test.bundle2", "1.0.0.201108100850");
}

public void testTargetPlatformAsSource() throws Exception {
Iu featureIU = new Iu();
featureIU.id = "test.feature.feature.group";
setVariableValueToObject(mirrorMojo, "ius", Collections.singletonList(featureIU));
setVariableValueToObject(mirrorMojo, "targetPlatformAsSource", Boolean.TRUE);
try {
// Source is allowed to be empty, for example when targetPlatformAsSource is set, but in this test
// project we have no target platform so it should fail gracefully instead of throwing a NPE
mirrorMojo.execute();
fail();
} catch (MojoExecutionException e) {
assertEquals(e.getMessage(), "No repository provided as 'source'");
}
}

private static void assertMirroredBundle(File publishedContentDir, String bundleID, String version) {
assertMirroredArtifact(publishedContentDir, bundleID, version, "plugins");
}
Expand Down

0 comments on commit 2e89f62

Please sign in to comment.