@Override
public void associate(final Project project, final DirectoryResource parentDir)
{
if (canAssociate(project, parentDir))
{
Project parent = projectFactory.findProject(parentDir);
MavenFacet parentMavenFacet = parent.getFacet(MavenFacet.class);
Model parentPom = parentMavenFacet.getPOM();
parentPom.setPackaging("pom");
String moduleDir = project.getProjectRoot().getFullyQualifiedName()
.substring(parent.getProjectRoot().getFullyQualifiedName().length());
if (moduleDir.startsWith("/"))
moduleDir = moduleDir.substring(1);
parentPom.addModule(moduleDir);
parentMavenFacet.setPOM(parentPom);
MavenFacet projectMavenFacet = project.getFacet(MavenFacet.class);
Model pom = projectMavenFacet.getPOM();
Parent projectParent = new Parent();
projectParent.setGroupId(parentPom.getGroupId());
projectParent.setArtifactId(parentPom.getArtifactId());
projectParent.setVersion(parentPom.getVersion());
DirectoryResource root = project.getProjectRoot();
DirectoryResource parentRoot = parent.getProjectRoot();
// Calculate parent relative path
String delta = root.getFullyQualifiedName().substring(parentRoot.getFullyQualifiedName().length());
String relativePath = delta.replaceAll("/(\\w+)", "../") + "pom.xml";
projectParent.setRelativePath(relativePath);