@Option(name = "parentProjectRoot",
description = "absolute location of a project to use as this project's direct parent",
required = false) final Resource<?> path,
final PipeOut out)
{
MavenCoreFacet mvn = project.getFacet(MavenCoreFacet.class);
Parent parent = null;
if (gav != null)
{
Assert.notNull(gav.getArtifactId(), "ArtifactId must not be null [" + gav.toCoordinates() + "]");
Assert.notNull(gav.getGroupId(), "GroupId must not be null [" + gav.toCoordinates() + "]");
Assert.notNull(gav.getVersion(), "Version must not be null [" + gav.toCoordinates() + "]");
parent = new Parent();
parent.setArtifactId(gav.getArtifactId());
parent.setGroupId(gav.getGroupId());
parent.setVersion(gav.getVersion());
if (relativePath != null)
{
parent.setRelativePath(relativePath);
}
Model pom = mvn.getPOM();
pom.setParent(parent);
mvn.setPOM(pom);
}
else if ((path != null) && factory.containsProject(path.reify(DirectoryResource.class)))
{
Project parentProject = factory.findProject(path.reify(DirectoryResource.class));
MavenCoreFacet parentCore = parentProject.getFacet(MavenCoreFacet.class);
parent = new Parent();
parent.setArtifactId(parentCore.getMavenProject().getArtifactId());
parent.setGroupId(parentCore.getMavenProject().getGroupId());
parent.setVersion(parentCore.getMavenProject().getVersion());
if (relativePath != null)
{
parent.setRelativePath(relativePath);
}
Model pom = mvn.getPOM();
pom.setParent(parent);
mvn.setPOM(pom);
}
else if (relativePath != null)
{
PathspecParser parser = new PathspecParser(resources, shell.getCurrentProject().getProjectRoot(), relativePath);
List<Resource<?>> resolvedResources = parser.resolve();
if (!resolvedResources.isEmpty()
&& factory.containsProject(resolvedResources.get(0).reify(DirectoryResource.class)))
{
Project parentProject = factory.findProject(resolvedResources.get(0).reify(DirectoryResource.class));
MavenCoreFacet parentCore = parentProject.getFacet(MavenCoreFacet.class);
parent = new Parent();
parent.setArtifactId(parentCore.getMavenProject().getArtifactId());
parent.setGroupId(parentCore.getMavenProject().getGroupId());
parent.setVersion(parentCore.getMavenProject().getVersion());
parent.setRelativePath(relativePath);
Model pom = mvn.getPOM();
pom.setParent(parent);
mvn.setPOM(pom);