private async getPomXmlSourceLocation()

in src/handlers/contentPreparer.ts [104:149]


    private async getPomXmlSourceLocation(packagePath: string): Promise<string> {
        const pomXmlPath: string = resolve(packagePath, 'pom.xml');
        if (!existsSync(pomXmlPath)) {
            Logger.Warn(`The file ${pomXmlPath} does not exist. ` +
                        "Please ensure your publish-profile setting points to a folder containing host.json.");
            Logger.Warn(`Fall back on ${packagePath} as packaging source.`);
            return packagePath;
        }

        let pomXmlContent: string = undefined;
        try {
            pomXmlContent = readFileSync(pomXmlPath, 'utf8');
        } catch (expt) {
            Logger.Warn(`The file ${pomXmlPath} does not have valid content. Please check if the pom.xml file is ` +
                        "and have proper encoding (utf-8).");
            Logger.Warn(`Fall back on ${packagePath} as packaging source.`);
            return packagePath
        }

        let pomXmlResult: any = undefined;
        await parseString(pomXmlContent, (error, xmlResult) => {
            if (!error) {
                pomXmlResult = xmlResult;
            }
        });
        if (!pomXmlResult) {
            Logger.Warn(`The xml file ${pomXmlPath} is invalid. Please check if the pom.xml file contains proper ` +
                        "content. Please visit https://maven.apache.org/pom.html#what-is-the-pom for more information.");
            Logger.Warn(`Fall back on ${packagePath} as packaging source.`);
            return packagePath;
        }

        let functionAppName: string = undefined;
        try {
            functionAppName = pomXmlResult.project.properties[0].functionAppName[0];
        } catch (expt) {
            Logger.Warn(`Cannot find functionAppName section in pom.xml. Please ensure the pom.xml is properly ` +
                        "generated from azure-functions maven plugin.");
            Logger.Warn(`Fall back on ${packagePath} as packaging source.`);
            return packagePath;
        }

        const pomPackagePath: string = resolve(packagePath, 'target', 'azure-functions', functionAppName);
        Logger.Info(`Successfully parsed pom.xml. Using ${pomPackagePath} as source folder for packaging`);
        return pomPackagePath;
    }