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,MAAM,EAAkB,CAAC,yBASzB,OARA,EAAO,EAAK,QAAQ,IACZ,EAAgB,SAAS,KACzB,SAAS,YAAY,uCACd,KAKR,EAAK,OAAO,QACvB,CAvOA,QAAQ,iBAAmB,iBAqI3B,QAAQ,+BAAiC,+BAmGzC,QAAQ,gBAAkB,CACtB,oBACA,wDACA,wCACA,wBACA,0BAA2B,2BAA2B","file":"/npm/snyk-gradle-plugin@5.1.1/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/snyk-gradle-plugin@5.1.1/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.exportsForTests = exports.processProjectsInExtractedJSON = exports.getGradleVersion = exports.inspect = exports.debugLog = void 0;\nconst os = require(\"os\");\nconst fs = require(\"fs\");\nconst path = require(\"path\");\nconst subProcess = require(\"./sub-process\");\nconst tmp = require(\"tmp\");\nconst pMap = require(\"p-map\");\nconst chalk = require(\"chalk\");\nconst cli_interface_1 = require(\"@snyk/cli-interface\");\nconst errors_1 = require(\"./errors\");\nconst gradle_attributes_pretty_1 = require(\"./gradle-attributes-pretty\");\nconst graph_1 = require(\"./graph\");\nconst search_1 = require(\"./search\");\nconst debugModule = require(\"debug\");\nconst coordinate_1 = require(\"./coordinate\");\n// To enable debugging output, use `snyk -d`\nlet logger = null;\nfunction debugLog(s) {\n    if (logger === null) {\n        // Lazy init: Snyk CLI needs to process the CLI argument \"-d\" first.\n        // TODO(BST-648): more robust handling of the debug settings\n        if (process.env.DEBUG) {\n            debugModule.enable(process.env.DEBUG);\n        }\n        logger = debugModule('snyk-gradle-plugin');\n    }\n    logger(s);\n}\nexports.debugLog = debugLog;\nconst cannotResolveVariantMarkers = [\n    'Cannot choose between the following',\n    'Could not select value from candidates',\n    'Unable to find a matching variant of project',\n];\n// General implementation. The result type depends on the runtime type of `options`.\nasync function inspect(root, targetFile, options, snykHttpClient) {\n    debugLog('Gradle inspect called with: ' +\n        JSON.stringify({\n            root,\n            targetFile,\n            allSubProjects: options === null || options === void 0 ? void 0 : options.allSubProjects,\n            subProject: options === null || options === void 0 ? void 0 : options.subProject,\n        }));\n    if (!options) {\n        options = { dev: false };\n    }\n    let subProject = options.subProject;\n    if (subProject) {\n        subProject = subProject.trim();\n        options.subProject = subProject;\n    }\n    const plugin = {\n        name: 'bundled:gradle',\n        runtime: 'unknown',\n        targetFile: targetFileFilteredForCompatibility(targetFile),\n        meta: {},\n    };\n    if (cli_interface_1.legacyPlugin.isMultiSubProject(options)) {\n        if (subProject) {\n            throw new Error('gradle-sub-project flag is incompatible with multiDepRoots');\n        }\n        const scannedProjects = await getAllDepsAllProjects(root, targetFile, options, snykHttpClient);\n        plugin.meta = plugin.meta || {};\n        return {\n            plugin,\n            scannedProjects,\n        };\n    }\n    const depGraphAndDepRootNames = await getAllDepsOneProject(root, targetFile, options, snykHttpClient, subProject);\n    if (depGraphAndDepRootNames.allSubProjectNames) {\n        plugin.meta = plugin.meta || {};\n        plugin.meta.allSubProjectNames = depGraphAndDepRootNames.allSubProjectNames;\n    }\n    return {\n        plugin,\n        package: null,\n        dependencyGraph: depGraphAndDepRootNames.depGraph,\n        meta: {\n            gradleProjectName: depGraphAndDepRootNames.gradleProjectName,\n            versionBuildInfo: depGraphAndDepRootNames.versionBuildInfo,\n        },\n    };\n}\nexports.inspect = inspect;\n// See the comment for DepRoot.targetFile\n// Note: for Gradle, we are not returning the name unless it's a .kts file.\n// This is a workaround for a project naming problem happening in Registry\n// (legacy projects are named without \"build.gradle\" attached to them).\n// See ticket BST-529 re permanent solution.\nfunction targetFileFilteredForCompatibility(targetFile) {\n    return path.basename(targetFile) === 'build.gradle.kts'\n        ? targetFile\n        : undefined;\n}\nfunction extractJsonFromScriptOutput(stdoutText) {\n    const lines = stdoutText.split('\\n');\n    let jsonLine = null;\n    lines.forEach((l) => {\n        if (/^JSONDEPS /.test(l)) {\n            if (jsonLine !== null) {\n                debugLog('More than one line with \"JSONDEPS \" prefix was returned;');\n                debugLog('First line: ' + jsonLine);\n                debugLog('Current line:' + l.substr(9));\n                // TODO (@tardis): the init.gradle should protect against this using 'snykDepsConfExecuted' flag\n                // the longer term fix here is to make multiple snyk graph outputs impossible by interacting with\n                // Gradle API in a more consistent way.\n                // For now, assume the first JSONDEPS found was correct\n                return;\n            }\n            jsonLine = l.substr(9);\n        }\n    });\n    if (jsonLine === null) {\n        throw new Error('No line prefixed with \"JSONDEPS \" was returned; full output:\\n' +\n            stdoutText);\n    }\n    debugLog('The command produced JSONDEPS output of ' +\n        jsonLine.length +\n        ' characters');\n    return JSON.parse(jsonLine);\n}\nasync function getAllDepsOneProject(root, targetFile, options, snykHttpClient, subProject) {\n    const allProjectDeps = await getAllDeps(root, targetFile, options, snykHttpClient);\n    const allSubProjectNames = allProjectDeps.allSubProjectNames;\n    return getTargetProject(subProject, allProjectDeps, allSubProjectNames);\n}\nfunction getTargetProject(subProject, allProjectDeps, allSubProjectNames) {\n    const { projects, defaultProject, defaultProjectKey, versionBuildInfo } = allProjectDeps;\n    let gradleProjectName = defaultProject;\n    if (subProject) {\n        // TODO: we don't want to break the existing implementation of --sub-project using name\n        // we would like a relative path instead to have a unique identifier\n        if (subProject != '.') {\n            subProject =\n                allSubProjectNames.find((it) => it === subProject) ||\n                    allSubProjectNames.find((it) => it.match(`/${subProject}`)) ||\n                    subProject;\n        }\n        if (!allProjectDeps.projects || !allProjectDeps.projects[subProject]) {\n            throw new errors_1.MissingSubProjectError(subProject, allSubProjectNames);\n        }\n        gradleProjectName = `${allProjectDeps.defaultProject}/${subProject}`;\n    }\n    const targetProject = subProject || defaultProjectKey;\n    const { depGraph } = projects[targetProject];\n    return {\n        depGraph,\n        allSubProjectNames,\n        gradleProjectName,\n        versionBuildInfo,\n    };\n}\nasync function getAllDepsAllProjects(root, targetFile, options, snykHttpClient) {\n    const allProjectDeps = await getAllDeps(root, targetFile, options, snykHttpClient);\n    return Object.keys(allProjectDeps.projects).map((projectId) => {\n        const { defaultProject } = allProjectDeps;\n        const gradleProjectName = projectId === defaultProject\n            ? defaultProject\n            : `${defaultProject}/${projectId}`;\n        const absoluteTargetFile = allProjectDeps.projects[projectId].targetFile;\n        const relativeTargetFile = path.relative(root, absoluteTargetFile);\n        return {\n            targetFile: relativeTargetFile,\n            meta: {\n                gradleProjectName,\n                projectName: gradleProjectName,\n                versionBuildInfo: allProjectDeps.versionBuildInfo,\n                targetFile: absoluteTargetFile,\n            },\n            depGraph: allProjectDeps.projects[projectId].depGraph,\n        };\n    });\n}\nconst reEcho = /^SNYKECHO (.*)$/;\nasync function printIfEcho(line) {\n    const maybeMatch = reEcho.exec(line);\n    if (maybeMatch) {\n        debugLog(maybeMatch[1]);\n    }\n}\nasync function injectedPlugin(scriptName) {\n    let initGradleAsset = null;\n    if (/index.js$/.test(__filename)) {\n        // running from ./dist\n        // path.join call has to be exactly in this format, needed by \"pkg\" to build a standalone Snyk CLI binary:\n        // https://www.npmjs.com/package/pkg#detecting-assets-in-source-code\n        initGradleAsset = path.join(__dirname, '../lib', scriptName);\n    }\n    else if (/index.ts$/.test(__filename)) {\n        // running from ./lib\n        initGradleAsset = path.join(__dirname, scriptName);\n    }\n    else {\n        throw new Error(`Cannot locate Snyk ${scriptName} script`);\n    }\n    // We could be running from a bundled CLI generated by `pkg`.\n    // The Node filesystem in that case is not real: https://github.com/zeit/pkg#snapshot-filesystem\n    // Copying the injectable script into a temp file.\n    try {\n        const tmpInitGradle = tmp.fileSync({ postfix: `-${scriptName}` });\n        fs.writeSync(tmpInitGradle.fd, fs.readFileSync(initGradleAsset));\n        return {\n            injectedPluginFilePath: tmpInitGradle.name,\n            cleanupCallback: tmpInitGradle.removeCallback,\n        };\n    }\n    catch (error) {\n        error.message =\n            error.message +\n                '\\n\\n' +\n                'Failed to create a temporary file to host Snyk init script for Gradle build analysis.';\n        throw error;\n    }\n}\n// when running a project is making use of gradle wrapper, the first time we run `gradlew -v`, the download\n// process happens, cluttering the parsing of the gradle output.\n// will extract the needed data using a regex\nfunction cleanupVersionOutput(gradleVersionOutput) {\n    // Everything since the first \"------\" line.\n    // [\\s\\S] used instead of . as it's the easiest way to match \\n too\n    const matchedData = gradleVersionOutput.match(/(-{60}[\\s\\S]+$)/g);\n    if (matchedData) {\n        return matchedData[0];\n    }\n    debugLog('cannot parse gradle version output:' + gradleVersionOutput);\n    return '';\n}\nfunction getVersionBuildInfo(gradleVersionOutput) {\n    try {\n        const cleanedVersionOutput = cleanupVersionOutput(gradleVersionOutput);\n        if (cleanedVersionOutput !== '') {\n            const gradleOutputArray = cleanedVersionOutput.split(/\\r\\n|\\r|\\n/);\n            // from first 3 new lines, we get the gradle version\n            const gradleVersion = gradleOutputArray[1].split(' ')[1].trim();\n            const versionMetaInformation = gradleOutputArray.slice(4);\n            // from line 4 until the end we get multiple meta information such as Java, Groovy, Kotlin, etc.\n            const metaBuildVersion = {};\n            // Select the lines in \"Attribute: value format\"\n            versionMetaInformation\n                .filter((value) => value && value.length > 0 && value.includes(': '))\n                .map((value) => value.split(/(.*): (.*)/))\n                .forEach((splitValue) => (metaBuildVersion[toCamelCase(splitValue[1].trim())] =\n                splitValue[2].trim()));\n            return {\n                gradleVersion,\n                metaBuildVersion,\n            };\n        }\n    }\n    catch (error) {\n        debugLog('version build info not present, skipping ahead: ' + error);\n    }\n}\nasync function getGradleVersion(root, command, args) {\n    debugLog('`gradle -v` command run: ' + command);\n    let gradleVersionOutput = '[COULD NOT RUN gradle -v]';\n    const completeArgs = args ? args.concat(['-v']) : ['-v'];\n    try {\n        gradleVersionOutput = await subProcess.execute(command, completeArgs, {\n            cwd: root,\n        });\n    }\n    catch (_) {\n        // intentionally empty\n    }\n    return gradleVersionOutput;\n}\nexports.getGradleVersion = getGradleVersion;\nasync function getAllDepsWithPlugin(root, targetFile, options, gradleVersion) {\n    const command = getCommand(root, targetFile);\n    const { injectedPluginFilePath, cleanupCallback } = await injectedPlugin('init.gradle');\n    const args = buildArgs(root, targetFile, injectedPluginFilePath, options, gradleVersion);\n    const fullCommandText = 'gradle command: ' + command + ' ' + args.join(' ');\n    debugLog('Executing ' + fullCommandText);\n    const stdoutText = await subProcess.execute(command, args, { cwd: root }, printIfEcho);\n    if (cleanupCallback) {\n        cleanupCallback();\n    }\n    const extractedJSON = extractJsonFromScriptOutput(stdoutText);\n    const jsonAttrsPretty = (0, gradle_attributes_pretty_1.getGradleAttributesPretty)(stdoutText);\n    logger(`The following attributes and their possible values were found in your configurations: ${jsonAttrsPretty}`);\n    return extractedJSON;\n}\nasync function getAllDeps(root, targetFile, options, snykHttpClient) {\n    const command = getCommand(root, targetFile);\n    const gradleVersion = await getGradleVersion(root, command, []);\n    if (gradleVersion.match(/Gradle 1/)) {\n        throw new Error('Gradle 1.x is not supported');\n    }\n    try {\n        const extractedJSON = await getAllDepsWithPlugin(root, targetFile, options, gradleVersion);\n        const versionBuildInfo = getVersionBuildInfo(gradleVersion);\n        if (versionBuildInfo) {\n            extractedJSON.versionBuildInfo = versionBuildInfo;\n        }\n        const sha1Map = {};\n        if (extractedJSON.sha1Map) {\n            const getCoordinateFromHash = async (hash) => {\n                const originalCoordinate = extractedJSON.sha1Map[hash];\n                const depCoord = (0, coordinate_1.parseCoordinate)(originalCoordinate);\n                try {\n                    const coordinate = await (0, search_1.getMavenPackageInfo)(hash, depCoord, snykHttpClient);\n                    sha1Map[hash] = coordinate;\n                }\n                catch (err) {\n                    debugLog(err);\n                }\n            };\n            await pMap(Object.keys(extractedJSON.sha1Map), getCoordinateFromHash, {\n                concurrency: 100,\n            });\n        }\n        return await processProjectsInExtractedJSON(extractedJSON, options['print-graph'], sha1Map);\n    }\n    catch (err) {\n        const error = err;\n        const gradleErrorMarkers = /^\\s*>\\s.*$/;\n        const gradleErrorEssence = error.message\n            .split('\\n')\n            .filter((l) => gradleErrorMarkers.test(l))\n            .join('\\n');\n        const orange = chalk.rgb(255, 128, 0);\n        const blackOnYellow = chalk.bgYellowBright.black;\n        const gradleVersionOutput = orange(gradleVersion);\n        let mainErrorMessage = `Error running Gradle dependency analysis.\n\nPlease ensure you are calling the \\`snyk\\` command with correct arguments.\nIf the problem persists, contact support@snyk.io, providing the full error\nmessage from above, starting with ===== DEBUG INFORMATION START =====.`;\n        // Special case for Android, where merging the configurations is sometimes\n        // impossible.\n        // There are no automated tests for this yet (setting up Android SDK is quite problematic).\n        // See test/manual/README.md\n        const jsonAttrsPretty = (0, gradle_attributes_pretty_1.getGradleAttributesPretty)(error.message);\n        if (jsonAttrsPretty) {\n            logger(`The following attributes and their possible values were found in your configurations: ${jsonAttrsPretty}`);\n        }\n        if (cannotResolveVariantMarkers.find((m) => error.message.includes(m))) {\n            mainErrorMessage = `Error running Gradle dependency analysis.\n\nIt seems like you are scanning an Android build with ambiguous dependency variants.\nWe cannot automatically resolve dependencies for such builds.\n\nYou have several options to make dependency resolution rules more specific:\n\n1. Run Snyk CLI tool with an attribute filter, e.g.:\n    ${chalk.whiteBright('snyk test --all-sub-projects --configuration-attributes=buildtype:release,usage:java-runtime')}\n\nThe filter will select matching attributes from those found in your configurations, use them\nto select matching configuration(s) to be used to resolve dependencies. Any sub-string of the full\nattribute name is enough.\n\nSelect the values for the attributes that would allow to unambiguously select the correct dependency\nvariant. The Gradle error message above should contain information about attributes found in\ndifferent variants.\n\nSuggested attributes: buildtype, usage and your \"flavor dimension\" for Android builds.\n\nThe following attributes and their possible values were found in your configurations:\n${jsonAttrsPretty}\n\n2. Run Snyk CLI tool for specific configuration(s), e.g.:\n    ${chalk.whiteBright(\"snyk test --gradle-sub-project=my-app --configuration-matching='^releaseRuntimeClasspath$'\")}\n\n(note that some configurations won't be present in every your subproject)\n\n3. Converting your subproject dependency specifications from the form of\n    ${chalk.whiteBright(\"implementation project(':mymodule')\")}\nto\n    ${chalk.whiteBright(\"implementation project(path: ':mymodule', configuration: 'default')\")}`;\n        }\n        error.message = `${chalk.red.bold('Gradle Error (short):\\n' + gradleErrorEssence)}\n\n${blackOnYellow('===== DEBUG INFORMATION START =====')}\n${orange(gradleVersionOutput)}\n${orange(error.message)}\n${blackOnYellow('===== DEBUG INFORMATION END =====')}\n\n${chalk.red.bold(mainErrorMessage)}`;\n        throw error;\n    }\n}\nasync function processProjectsInExtractedJSON(extractedJSON, verbose, sha1Map) {\n    for (const projectId in extractedJSON.projects) {\n        const { defaultProject, defaultProjectKey } = extractedJSON;\n        const { gradleGraph, projectVersion } = extractedJSON.projects[projectId];\n        if (!gradleGraph) {\n            continue;\n        }\n        const isSubProject = projectId !== defaultProjectKey;\n        let rootPkgName = defaultProject;\n        if (isSubProject) {\n            rootPkgName = `${defaultProject}/${projectId}`;\n        }\n        extractedJSON.projects[projectId].depGraph = await (0, graph_1.buildGraph)(gradleGraph, rootPkgName, projectVersion, verbose, sha1Map);\n        // this property usage ends here\n        delete extractedJSON.projects[projectId].gradleGraph;\n    }\n    return extractedJSON;\n}\nexports.processProjectsInExtractedJSON = processProjectsInExtractedJSON;\nfunction toCamelCase(input) {\n    input = input\n        .toLowerCase()\n        .replace(/(?:(^.)|([-_\\s]+.))/g, (match) => {\n        return match.charAt(match.length - 1).toUpperCase();\n    });\n    return input.charAt(0).toLowerCase() + input.substring(1);\n}\nfunction getCommand(root, targetFile) {\n    const isWinLocal = /^win/.test(os.platform()); // local check, can be stubbed in tests\n    const wrapperScript = isWinLocal ? 'gradlew.bat' : './gradlew';\n    // try to find a sibling wrapper script first\n    let pathToWrapper = path.resolve(root, path.dirname(targetFile), wrapperScript);\n    if (fs.existsSync(pathToWrapper)) {\n        return pathToWrapper;\n    }\n    // now try to find a wrapper in the root\n    pathToWrapper = path.resolve(root, wrapperScript);\n    if (fs.existsSync(pathToWrapper)) {\n        return pathToWrapper;\n    }\n    return 'gradle';\n}\nfunction buildArgs(root, targetFile, initGradlePath, options, gradleVersion) {\n    let args = [];\n    const taskName = options.gradleNormalizeDeps\n        ? 'snykNormalizedResolvedDepsJson'\n        : 'snykResolvedDepsJson';\n    args.push(taskName, '-q');\n    if (targetFile) {\n        const resolvedTargetFilePath = path.resolve(root, targetFile);\n        if (!fs.existsSync(resolvedTargetFilePath)) {\n            throw new Error('File not found: \"' + resolvedTargetFilePath + '\"');\n        }\n        const resolvedTargetDir = path.dirname(resolvedTargetFilePath);\n        args.push('--project-dir');\n        args.push(resolvedTargetDir);\n    }\n    // Arguments to init script are supplied as properties: https://stackoverflow.com/a/48370451\n    if (options['configuration-matching']) {\n        args.push(`-Pconfiguration=${options['configuration-matching']}`);\n    }\n    if (options['configuration-attributes']) {\n        args.push(`-PconfAttr=${options['configuration-attributes']}`);\n    }\n    if (options.initScript) {\n        const formattedInitScript = path.resolve(options.initScript);\n        args.push('--init-script', formattedInitScript);\n    }\n    const isWin = /^win/.test(os.platform());\n    if (isWin && !options.daemon) {\n        args.push('--no-daemon');\n    }\n    // Parallel builds can cause race conditions and multiple JSONDEPS lines in the output\n    // Gradle 4.3.0+ has `--no-parallel` flag, but we want to support older versions.\n    // Not `=false` to be compatible with 3.5.x: https://github.com/gradle/gradle/issues/1827\n    args.push('-Dorg.gradle.parallel=');\n    // Since version 4.3.0+ Gradle uses different console output mechanism. Default mode is 'auto',\n    // if Gradle is attached to a terminal. It means build output will use ANSI control characters\n    // to generate the rich output, therefore JSON cannot be parsed.\n    args.push('-Dorg.gradle.console=plain');\n    if (!cli_interface_1.legacyPlugin.isMultiSubProject(options)) {\n        args.push('-PonlySubProject=' + (options.subProject || '.'));\n    }\n    args.push('-I', initGradlePath);\n    if (options.args) {\n        args.push(...options.args);\n    }\n    // Gradle 7 introduced configuration caching which we don't support yet\n    // If it is enabled in a gradle.properties file, it can be disabled on the command line with --no-configuration-cache\n    // It is enabled by default in Gradle 9.\n    // The regex matches Gradle 7, 8, 9 and any future two-digit versions (10, 11, etc.).\n    if (gradleVersion.match(/Gradle ([7-9]|\\d{2,})/)) {\n        args.push('--no-configuration-cache');\n    }\n    // There might be a legacy --configuration option in 'args'.\n    // It has been superseded by --configuration-matching option for Snyk CLI (see buildArgs),\n    // but we are handling it to support the legacy setups.\n    args.forEach((a, i) => {\n        // Transform --configuration=foo\n        args[i] = a.replace(/^--configuration[= ]([a-zA-Z_]+)/, `-Pconfiguration=^$1$$`);\n        // Transform --configuration foo\n        if (a === '--configuration') {\n            args[i] = `-Pconfiguration=^${args[i + 1]}$`;\n            args[i + 1] = '';\n        }\n    });\n    const unsupportedArgs = ['--configuration-cache'];\n    args = args.filter((arg) => {\n        if (unsupportedArgs.includes(arg)) {\n            debugLog(`Argument ${arg} not currently supported by Snyk.`);\n            return false;\n        }\n        else\n            return true;\n    });\n    return args.filter(Boolean);\n}\nexports.exportsForTests = {\n    buildArgs,\n    extractJsonFromScriptOutput,\n    getVersionBuildInfo,\n    toCamelCase,\n    getGradleAttributesPretty: gradle_attributes_pretty_1.getGradleAttributesPretty,\n};\n"]}