From 5eb3ecd5ad5d21c9f455ef3d91f5de5f460726c8 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 15 Dec 2017 12:02:04 +0100 Subject: [PATCH] [core] Make sure, a language with empty version selects the default version --- .../net/sourceforge/pmd/lang/LanguageRegistry.java | 4 +++- .../sourceforge/pmd/lang/LanguageRegistryTest.java | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java index 9fc1f2d48b..4de50951d1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java @@ -14,6 +14,8 @@ import java.util.List; import java.util.Map; import java.util.ServiceLoader; +import org.apache.commons.lang3.StringUtils; + /** * Created by christoferdutz on 20.09.14. */ @@ -90,7 +92,7 @@ public final class LanguageRegistry { String version; String terseName; if (terseNameAndVersion.contains(" ")) { - version = terseNameAndVersion.substring(terseNameAndVersion.lastIndexOf(' ') + 1); + version = StringUtils.trimToNull(terseNameAndVersion.substring(terseNameAndVersion.lastIndexOf(' ') + 1)); terseName = terseNameAndVersion.substring(0, terseNameAndVersion.lastIndexOf(' ')); } else { version = null; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageRegistryTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageRegistryTest.java index 7c67d740f6..8feaaa7f28 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageRegistryTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageRegistryTest.java @@ -17,4 +17,17 @@ public class LanguageRegistryTest { // available language now -> DummyLanguage Assert.assertSame(DummyLanguageModule.class, defaultLanguage.getClass()); } + + @Test + public void getDefaultVersionLanguageTest() { + LanguageVersion dummy12 = LanguageRegistry.findLanguageVersionByTerseName("dummy 1.2"); + Assert.assertNotNull(dummy12); + + Language dummy = LanguageRegistry.findLanguageByTerseName("dummy"); + LanguageVersion dummyDefault = dummy.getDefaultVersion(); + + LanguageVersion dummyDefault2 = LanguageRegistry.findLanguageVersionByTerseName("dummy "); + Assert.assertNotNull(dummyDefault2); + Assert.assertSame(dummyDefault, dummyDefault2); + } }