@Test public void testPartMatch() { assertTrue(AntArtifactMatcher.patternMatches("abc", "abc")); assertFalse(AntArtifactMatcher.patternMatches("abcd", "abc")); assertTrue(AntArtifactMatcher.patternMatches("", "abc")); assertTrue(AntArtifactMatcher.patternMatches("*", "abc")); assertTrue(AntArtifactMatcher.patternMatches("abc*", "abc")); assertTrue(AntArtifactMatcher.patternMatches("abc*", "abcde")); assertFalse(AntArtifactMatcher.patternMatches("abc*", "ab")); assertFalse(AntArtifactMatcher.patternMatches("abc*", "xabcd")); assertTrue(AntArtifactMatcher.patternMatches("*cde", "abcde")); assertTrue(AntArtifactMatcher.patternMatches("*cde", "bcde")); assertTrue(AntArtifactMatcher.patternMatches("*cde", "cde")); assertTrue(AntArtifactMatcher.patternMatches("*cde*", "cde")); assertTrue(AntArtifactMatcher.patternMatches("*cde*", "abcdefg")); }
static boolean patternMatches(String pattern, @Nullable String s) { if (pattern.isEmpty() || pattern.equals("*")) { return true; } if (s == null) { return false; } if (pattern.startsWith("*") && pattern.endsWith("*")) { return s.contains(pattern.substring(1, pattern.length() - 1)); } if (pattern.startsWith("*")) { return s.endsWith(pattern.substring(1)); } if (pattern.endsWith("*")) { return s.startsWith(pattern.substring(0, pattern.length() - 1)); } return pattern.equals(s); }
AntArtifactMatcher implements ArtifactMatcher { static boolean patternMatches(String pattern, @Nullable String s) { if (pattern.isEmpty() || pattern.equals("*")) { return true; } if (s == null) { return false; } if (pattern.startsWith("*") && pattern.endsWith("*")) { return s.contains(pattern.substring(1, pattern.length() - 1)); } if (pattern.startsWith("*")) { return s.endsWith(pattern.substring(1)); } if (pattern.endsWith("*")) { return s.startsWith(pattern.substring(0, pattern.length() - 1)); } return pattern.equals(s); } }
AntArtifactMatcher implements ArtifactMatcher { static boolean patternMatches(String pattern, @Nullable String s) { if (pattern.isEmpty() || pattern.equals("*")) { return true; } if (s == null) { return false; } if (pattern.startsWith("*") && pattern.endsWith("*")) { return s.contains(pattern.substring(1, pattern.length() - 1)); } if (pattern.startsWith("*")) { return s.endsWith(pattern.substring(1)); } if (pattern.endsWith("*")) { return s.startsWith(pattern.substring(0, pattern.length() - 1)); } return pattern.equals(s); } AntArtifactMatcher(String pattern); }
AntArtifactMatcher implements ArtifactMatcher { static boolean patternMatches(String pattern, @Nullable String s) { if (pattern.isEmpty() || pattern.equals("*")) { return true; } if (s == null) { return false; } if (pattern.startsWith("*") && pattern.endsWith("*")) { return s.contains(pattern.substring(1, pattern.length() - 1)); } if (pattern.startsWith("*")) { return s.endsWith(pattern.substring(1)); } if (pattern.endsWith("*")) { return s.startsWith(pattern.substring(0, pattern.length() - 1)); } return pattern.equals(s); } AntArtifactMatcher(String pattern); @Override boolean matches(Artifact artifact); }
AntArtifactMatcher implements ArtifactMatcher { static boolean patternMatches(String pattern, @Nullable String s) { if (pattern.isEmpty() || pattern.equals("*")) { return true; } if (s == null) { return false; } if (pattern.startsWith("*") && pattern.endsWith("*")) { return s.contains(pattern.substring(1, pattern.length() - 1)); } if (pattern.startsWith("*")) { return s.endsWith(pattern.substring(1)); } if (pattern.endsWith("*")) { return s.startsWith(pattern.substring(0, pattern.length() - 1)); } return pattern.equals(s); } AntArtifactMatcher(String pattern); @Override boolean matches(Artifact artifact);  }