boolean checkIsDead()

in buildSrc/src/main/groovy/util/CheckLinks.groovy [37:86]


    boolean checkIsDead(String link, currentPath) {
        if (excludeFromChecks.any { link.startsWith(it) || (!it.startsWith('http') && link.endsWith(it)) }) {
            // skip checking those links because they dramatically increase build time
            // while being most likely ok because generated through changelog parsing
            return false
        }

        try {
            URL url
            boolean rejected = false
            try {
                url = URI.create(link).toURL()
            } catch (e) {
                if (e.message.contains('URI is not absolute')) {
                    rejected = true
                }
            }
            if (rejected || !url) {
                def path = "file:///${new File("$baseDir/${currentPath ? currentPath + '/' : ''}$link").canonicalPath.replace('\\', '/')}"
                url = URI.create(path).toURL()
                link = url.file
            }
            logger?.debug("Checking URL: $url")
            def cx = url.openConnection()
            if (cx instanceof HttpURLConnection) {
                CloseableHttpClient httpclient = HttpClients.createDefault()
                RequestConfig requestConfig = RequestConfig.custom()
                        .setSocketTimeout(20_000)
                        .setConnectTimeout(20_000)
                        .setConnectionRequestTimeout(20_000)
                        .setCookieSpec(CookieSpecs.STANDARD)
                        .build()
                HttpGet httpget = new HttpGet(link)
                httpget.config = requestConfig
                CloseableHttpResponse response
                try {
                    response = httpclient.execute(httpget)
                    if (response.statusLine.statusCode == 404) {
                        return true
                    }
                } finally {
                    response.close()
                }
            }
        } catch (e) {
            logger?.debug e.message
            return true
        }
        return false
    }