Skip to content
Open
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 @@ -130,13 +130,18 @@ private void validateArtifactGav(final Artifact artifact) {
version = artifactPom.getVersion();
}

final Model model = getPom().getModel(this);
final Pom pom = getPom();
if (pom == null) {
throw new BuildException("You must specify the <pom file=\"...\"> element"
+ " to denote the descriptor for the artifacts");
}
final Model model = pom.getModel(this);

if (!(model.getGroupId().equals(gid)
&& model.getArtifactId().equals(aid)
&& model.getVersion().equals(version))) {
throw new BuildException(
"Artifact references different pom than it would be installed with: " + artifact.toString());
"Artifact references different pom than it would be installed with: " + artifact);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Arrays;

import junit.framework.JUnit4TestAdapter;
import org.apache.tools.ant.BuildException;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -30,6 +31,7 @@
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasItemInArray;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.fail;

/*
* still missing:
Expand Down Expand Up @@ -96,4 +98,33 @@ private void assertUpdatedFile(long min, long max, File repoPath, String path) {
file.lastModified(),
allOf(greaterThanOrEqualTo(min), lessThanOrEqualTo(max)));
}

/**
* Reproduces an NPE when a deploy &lt;artifact&gt; contains only a nested &lt;pom/&gt;.
* <pre>{@code
* <repo:deploy>
* <repo:artifact file="${artifact.file}">
* <repo:pom file="${project.dir}/dummy-pom.xml"/>
* </repo:artifact>
* <repo:snapshotrepo refid="Snapshots"/>
* </repo:deploy>
* }</pre>
* Current behavior: Ant build fails with a NullPointerException at the root cause.
* Once the deploy task supports this case or throws a clearer error, update the assertion accordingly.
*/
@Test
public void testDeployOnlyNestedPomException() {
try {
executeTarget("testDeployOnlyNestedPomException");
fail("Expected the build to fail when deploying with only a nested <pom/> inside <artifact>.");
} catch (Exception e) {
Throwable cause = e;
while (cause.getCause() != null) {
cause = cause.getCause();
}
if (!(cause instanceof BuildException)) {
fail("Expected NullPointerException as root cause, but was: " + cause);
}
}
}
}
22 changes: 22 additions & 0 deletions src/test/resources/ant/Deploy/ant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,26 @@
</repo:deploy>
</target>

<!--
Only a nested <pom/> inside <resolver:artifact>.
The DeployTest expects this target to fail with a BuildException.
-->
<target name="testDeployOnlyNestedPomException">
<property name="artifact.file" value="${build.dir}/dummy-artifact.jar"/>
<property name="temp.dir" value="${build.dir}/temp"/>
<property name="temp.content.file" value="${temp.dir}/content.txt"/>
<echo file="${temp.content.file}" append="false">
This is a test artifact content.
</echo>
<jar destfile="${artifact.file}">
<fileset dir="${temp.dir}">
<include name="content.txt"/>
</fileset>
</jar>
<repo:deploy>
<repo:artifact file="${artifact.file}">
<repo:pom file="${project.dir}/dummy-pom.xml"/>
</repo:artifact>
</repo:deploy>
</target>
</project>