diff --git a/pom.xml b/pom.xml index 1ceded14..17eef691 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ org.jenkins-ci.plugins plugin - 4.1 + 4.17 @@ -67,7 +67,7 @@ 2.6.5 -SNAPSHOT - 2.176.4 + 2.222.4 8 false 2.0.0 @@ -90,8 +90,8 @@ io.jenkins.tools.bom - bom-2.176.x - 9 + bom-2.222.x + 26 import pom diff --git a/src/main/java/jenkins/scm/api/SCMName.java b/src/main/java/jenkins/scm/api/SCMName.java index 0989ec2e..9d2bfbd4 100644 --- a/src/main/java/jenkins/scm/api/SCMName.java +++ b/src/main/java/jenkins/scm/api/SCMName.java @@ -27,12 +27,16 @@ import com.google.common.net.InternetDomainName; import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.IDN; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; import java.util.List; import java.util.Locale; + import org.apache.commons.lang.StringUtils; /** @@ -142,10 +146,32 @@ private static String resolveInternetDomainName(String hostName) { } if (host.hasPublicSuffix()) { - final String publicName = host.publicSuffix().name(); - return StringUtils.removeEnd(StringUtils.removeEnd(host.name(), publicName), ".").toLowerCase(Locale.ENGLISH); + final String publicName = name(host.publicSuffix()); + return StringUtils.removeEnd(StringUtils.removeEnd(name(host), publicName), ".").toLowerCase(Locale.ENGLISH); } - return StringUtils.removeEnd(host.name(), ".").toLowerCase(Locale.ENGLISH); + return StringUtils.removeEnd(name(host), ".").toLowerCase(Locale.ENGLISH); + } + + /** + * The full domain name, converted to lower case. + * It calls {@code InternetDomainName#name()} or falls back to {@link InternetDomainName#toString()} + * for compatibility with newer (> 22.0) versions of guava. + * + * @since TODO + */ + private static String name(InternetDomainName host) { + try { + try { + // Guava older than ~22 + Method method = InternetDomainName.class.getMethod("name"); + return (String) method.invoke(host); + } catch (NoSuchMethodException e) { + // TODO invert this to prefer the newer guava method once guava is upgrade in Jenkins core + return host.toString(); + } + } catch (IllegalAccessException | InvocationTargetException e ) { + throw new RuntimeException(e); + } } } diff --git a/src/test/java/jenkins/scm/api/MessagesTest.java b/src/test/java/jenkins/scm/api/MessagesTest.java deleted file mode 100644 index 303c2bcf..00000000 --- a/src/test/java/jenkins/scm/api/MessagesTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2016 CloudBees, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package jenkins.scm.api; - -import java.lang.reflect.Method; -import org.junit.Test; -import org.junit.experimental.theories.DataPoints; -import org.junit.experimental.theories.Theories; -import org.junit.experimental.theories.Theory; -import org.junit.runner.RunWith; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.notNullValue; - -/** - * The code coverage for the generated Messages class doesn't matter, so this test stops them from dragging the coverage - * down and results in a clearer measure of code coverage for the module. - */ -@RunWith(Theories.class) -public class MessagesTest { - @DataPoints - public static Method[] hack() { - return Messages.class.getDeclaredMethods(); - } - - @Theory - public void coverage(Method method) throws Exception { - Class[] types = method.getParameterTypes(); - Object[] args = new Object[types.length]; - for (int i = 0; i < types.length; i++) { - args[i] = (long) i; // long works as a number, string and date - } - assertThat(method.invoke(null, args), notNullValue()); - } - - @Test - public void constructor() throws Exception { - new Messages(); - } -} diff --git a/src/test/java/jenkins/scm/impl/MessagesTest.java b/src/test/java/jenkins/scm/impl/MessagesTest.java deleted file mode 100644 index fec560ea..00000000 --- a/src/test/java/jenkins/scm/impl/MessagesTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2016 CloudBees, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package jenkins.scm.impl; - -import java.lang.reflect.Method; -import org.junit.Test; -import org.junit.experimental.theories.DataPoints; -import org.junit.experimental.theories.Theories; -import org.junit.experimental.theories.Theory; -import org.junit.runner.RunWith; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.notNullValue; - -/** - * The code coverage for the generated Messages class doesn't matter, so this test stops them from dragging the coverage - * down and results in a clearer measure of code coverage for the module. - */ -@RunWith(Theories.class) -public class MessagesTest { - @DataPoints - public static Method[] hack() { - return Messages.class.getDeclaredMethods(); - } - - @Theory - public void coverage(Method method) throws Exception { - Class[] types = method.getParameterTypes(); - Object[] args = new Object[types.length]; - for (int i = 0; i < types.length; i++) { - args[i] = (long) i; // long works as a number, string and date - } - assertThat(method.invoke(null, args), notNullValue()); - } - - @Test - public void constructor() throws Exception { - new Messages(); - } -}