protected void buildModule(Document doc, Map<Artifact, String> moduleMap) throws MojoFailureException, XPathExpressionException {

        // check if there is a mapping in the dictionary for the project artifact
        DictItem mapping = dictionary.find(project.getGroupId(), project.getArtifactId(), project.getVersion());
        if (mapping == null || mapping.moduleName == null) {
            throw new MojoFailureException("No mapping found for the project artifact: " + project.getArtifact());
        }

        Element root = doc.getDocumentElement();
        if (!root.getTagName().equals("module"))
            throw new MojoFailureException("Root element is not module");
        root.setAttribute("name", mapping.moduleName);

        Element dependencies = (Element) xp_dependencies.evaluate(doc, XPathConstants.NODE);
        if (dependencies == null) {
            dependencies = doc.createElement("dependencies");
            root.insertBefore(dependencies, root.getFirstChild());
        }

        Element resources = (Element) xp_resources.evaluate(doc, XPathConstants.NODE);
        if (resources == null) {
            resources = doc.createElement("resources");
            root.insertBefore(resources, root.getFirstChild());
        }

        Element resource_root = (Element) xp_resource_root.evaluate(doc, XPathConstants.NODE);
        if (resource_root == null) {
            resource_root = doc.createElement("resource-root");
            resources.appendChild(resource_root);
        }

        // set resource-root path attribute
        resource_root.setAttribute("path", buildFinalName+"."+project.getPackaging());

        for (Map.Entry<Artifact, String> entry : moduleMap.entrySet()) {
            String module = entry.getValue();
            XPathExpression xp = xpf.newXPath().compile("module [@name=\"" + module + "\"]");
            if (xp.evaluate(dependencies, XPathConstants.NODE) == null) {
                Element moduleEl = doc.createElement("module");
                moduleEl.setAttribute("name", module);
                dependencies.appendChild(moduleEl);
            }
        }
    }