From 97cf48e9cfbbafef1833869b809884ef2b5b3498 Mon Sep 17 00:00:00 2001 From: Marco Rizzi Date: Wed, 10 Jan 2024 10:59:49 +0100 Subject: [PATCH 1/3] WindupRulesLinksTest: implemented retries for links' test (#1047) Signed-off-by: mrizzi --- .../rules/tests/WindupRulesLinksTest.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java b/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java index 65e80baae..c5497c2b2 100644 --- a/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java +++ b/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java @@ -75,6 +75,8 @@ public class WindupRulesLinksTest { CERT_FAILURE_LINKS.add("https://in.relation.to/2015/05/11/hibernate-search-530-beta-1-with-native-lucene-faceting/"); } + private static final int RETRIES = 5; + @Parameterized.Parameters(name = "{index}: Test {0}") public static Iterable data() { @@ -158,14 +160,19 @@ private boolean isValidLink(final String link) try { final long starTime = System.currentTimeMillis(); + int returnCode = 0; if (!CACHE_ANALYZED_LINKS.containsKey(link)) { - final URL url = new URL(link); - final HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); - // property name from https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html - urlConn.setConnectTimeout(Integer.getInteger("sun.net.client.defaultConnectTimeout", 5000)); - urlConn.connect(); - CACHE_ANALYZED_LINKS.put(link, urlConn.getResponseCode()); + for (int retry = 0; !ACCEPTED_RESPONSE_CODE.contains(returnCode) && retry < RETRIES; retry++) { + if (retry > 0) LOG.warn(String.format("Tentative #%d to connect to %s", retry + 1, link)); + final URL url = new URL(link); + final HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); + // property name from https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html + urlConn.setConnectTimeout(Integer.getInteger("sun.net.client.defaultConnectTimeout", 5000)); + urlConn.connect(); + returnCode = urlConn.getResponseCode(); + } + CACHE_ANALYZED_LINKS.put(link, returnCode); } final boolean validLink = ACCEPTED_RESPONSE_CODE.contains(CACHE_ANALYZED_LINKS.get(link)); if (validLink) LOG.debug(String.format("Response code %d for %s [%dms]", CACHE_ANALYZED_LINKS.get(link), link, System.currentTimeMillis() - starTime)); From 8705fa8e207bf57cbc44c0c144693b2807ebe4d3 Mon Sep 17 00:00:00 2001 From: Marco Rizzi Date: Wed, 10 Jan 2024 15:02:51 +0100 Subject: [PATCH 2/3] Update broken links in OpenJDK rules (#1049) Signed-off-by: mrizzi --- .../openjdk11/openjdk8/java-removals.windup.xml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rules/rules-reviewed/openjdk11/openjdk8/java-removals.windup.xml b/rules/rules-reviewed/openjdk11/openjdk8/java-removals.windup.xml index 6e7df0302..41193fef7 100644 --- a/rules/rules-reviewed/openjdk11/openjdk8/java-removals.windup.xml +++ b/rules/rules-reviewed/openjdk11/openjdk8/java-removals.windup.xml @@ -47,7 +47,8 @@ As such, the use of `sun.reflect.Reflection` class and particular the `getCallerClass` method should no longer be needed. Refer to the example changeset linked below. - + + @@ -64,7 +65,8 @@ `sun.reflect.CallerSensitive` annotation was deprecated in Java 9. Refer to the example changeset linked below. - + + @@ -196,7 +198,8 @@ In the long term, please consider using Variable Handles (see the link below) - + + @@ -216,7 +219,8 @@ For further examples on how to replace the `BASE64{encoder-decoder}` class with `Base64.{encoder-decoder}` one, refer to the "Code example" link below. - + + From f1d379b9b077b2755dffc5e094e33a1af58283c0 Mon Sep 17 00:00:00 2001 From: Marco Rizzi Date: Tue, 16 Jan 2024 15:38:32 +0100 Subject: [PATCH 3/3] Include IOException in the retry mechanism (#1052) * Include IOException in the retry mechanism Signed-off-by: mrizzi * Added 'User-Agent' property to links test Signed-off-by: mrizzi --------- Signed-off-by: mrizzi --- .../rules/tests/WindupRulesLinksTest.java | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java b/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java index c5497c2b2..168a51fc9 100644 --- a/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java +++ b/rules/src/test/java/org/jboss/windup/rules/tests/WindupRulesLinksTest.java @@ -37,12 +37,12 @@ * This tests all the href attribute in ALL the rules every time the tests are executed (PR and nightly builds) * Helpful to ensure we have always links that points to something so that links are really helpful for the user * Optimized with a very basic cache for not checking more than once the same URL - * + *

* The runTestsMatching is available in this test - * + *

* To change the connection timeout use the standard "-Dsun.net.client.defaultConnectTimeout=" property * from https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html - * + *

* To quickly see the debug log, execute the test with the property "-Dorg.slf4j.simpleLogger.log.org.jboss.windup=debug" */ @RunWith(Parameterized.class) @@ -158,30 +158,31 @@ private boolean isValidLink(final String link) if (CERT_FAILURE_LINKS.contains(link)) return true; - try { - final long starTime = System.currentTimeMillis(); - int returnCode = 0; - if (!CACHE_ANALYZED_LINKS.containsKey(link)) - { - for (int retry = 0; !ACCEPTED_RESPONSE_CODE.contains(returnCode) && retry < RETRIES; retry++) { - if (retry > 0) LOG.warn(String.format("Tentative #%d to connect to %s", retry + 1, link)); + final long starTime = System.currentTimeMillis(); + int returnCode = 0; + if (!CACHE_ANALYZED_LINKS.containsKey(link)) { + for (int retry = 0; !ACCEPTED_RESPONSE_CODE.contains(returnCode) && retry < RETRIES; retry++) { + if (retry > 0) LOG.warn(String.format("Tentative #%d to connect to %s", retry + 1, link)); + try { final URL url = new URL(link); final HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); // property name from https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html urlConn.setConnectTimeout(Integer.getInteger("sun.net.client.defaultConnectTimeout", 5000)); + urlConn.addRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0"); urlConn.connect(); returnCode = urlConn.getResponseCode(); + } catch (IOException e) { + LOG.error(String.format("'%s' exception connecting to %s", e.getMessage(), link), e); } - CACHE_ANALYZED_LINKS.put(link, returnCode); } - final boolean validLink = ACCEPTED_RESPONSE_CODE.contains(CACHE_ANALYZED_LINKS.get(link)); - if (validLink) LOG.debug(String.format("Response code %d for %s [%dms]", CACHE_ANALYZED_LINKS.get(link), link, System.currentTimeMillis() - starTime)); - else LOG.error(String.format("Response code %d for %s [%dms]", CACHE_ANALYZED_LINKS.get(link), link, System.currentTimeMillis() - starTime)); - return validLink; - } catch (IOException e) { - LOG.error(String.format("'%s' exception connecting to %s", e.getMessage(), link), e); - return false; + CACHE_ANALYZED_LINKS.put(link, returnCode); } + final boolean validLink = ACCEPTED_RESPONSE_CODE.contains(CACHE_ANALYZED_LINKS.get(link)); + if (validLink) + LOG.debug(String.format("Response code %d for %s [%dms]", CACHE_ANALYZED_LINKS.get(link), link, System.currentTimeMillis() - starTime)); + else + LOG.error(String.format("Response code %d for %s [%dms]", CACHE_ANALYZED_LINKS.get(link), link, System.currentTimeMillis() - starTime)); + return validLink; } private String buildListOfFailedRulesLinks(final Map> failedRulesWithLinks)