IndexedRegularExpressionIncludeResolver extends RegularExpressionIncludeResolver { @Override @Nullable public SimpleIncludeValue resolve(@NotNull File includeFolder) { Matcher match = LexicalIncludePaths.matchFolderToRegex(getCompiledMatchPattern(), includeFolder); if (!match.find()) { return null; } try { String relativeFolder = match.group("relative"); String libraryName = myLibraryName; if (libraryName == null) { libraryName = match.group("library"); } String homeFolder = match.group("home"); String description = myKind.myDescription; String version = groupOrNull(match, "ndk"); if (version != null) { Revision revision = Revision.parseRevision(version); if (revision.getMinor() == 0) { description += String.format(" r%s", revision.getMajor()); } else { char minor = (char)((int)'a' + revision.getMinor()); description += String.format(" r%s%s", revision.getMajor(), minor); } } return new SimpleIncludeValue(myKind, description, libraryName, relativeFolder, includeFolder, new File(homeFolder)); } catch (IllegalArgumentException e) { throw new RuntimeException(String.format("Pattern %s is missing a group name", myPattern), e); } } IndexedRegularExpressionIncludeResolver(
    @NotNull PackageType kind,
    @NotNull String pattern,
    @Nullable String libraryName); @Override @Nullable SimpleIncludeValue resolve(@NotNull File includeFolder);  }
@Test public void testLibraryVariationNoMatch() { IndexedRegularExpressionIncludeResolver resolver = new IndexedRegularExpressionIncludeResolver(PackageType.NdkComponent, "^(/path/to/ndk-bundle)(/sources/android/native_app_glue(/.*))$", "Native App Glue"); SimpleIncludeValue result = resolver.resolve(new File(".")); assertThat(result).isNull(); }
@Test public void testLibraryVariationMatch() { IndexedRegularExpressionIncludeResolver resolver = new IndexedRegularExpressionIncludeResolver(PackageType.NdkComponent, "^(?<home>/path/to/ndk-bundle)(?<relative>/sources/android/native_app_glue(/.*))$", "Native App Glue"); SimpleIncludeValue result = resolver.resolve(new File("/path/to/ndk-bundle/sources/android/native_app_glue")); assertThat(result).isNotNull(); assertThat(result.getSimplePackageName()).isEqualTo("Native App Glue"); assertThat(result.getRelativeIncludeSubFolder()).isEqualTo("/sources/android/native_app_glue/"); assertThat(result.getIncludeFolder()).isEqualTo(new File("/path/to/ndk-bundle/sources/android/native_app_glue")); }
@Test public void testNoLibraryVariationNoMatch() { IndexedRegularExpressionIncludeResolver resolver = new IndexedRegularExpressionIncludeResolver(PackageType.ThirdParty, "^(.*)(/third[_-]party/(.*?)/.*)$", null); SimpleIncludeValue result = resolver.resolve(new File(".")); assertThat(result).isNull(); }
@Test public void testNoLibraryVariationMatch() { IndexedRegularExpressionIncludeResolver resolver = new IndexedRegularExpressionIncludeResolver(PackageType.ThirdParty, "^(?<home>.*)(?<relative>/third[_-]party/(?<library>.*?)/.*)$", null); SimpleIncludeValue result = resolver.resolve(new File("/path/to/third_party/include")); assertThat(result).isNotNull(); assertThat(result.getSimplePackageName()).isEqualTo("include"); assertThat(result.getRelativeIncludeSubFolder()).isEqualTo("/third_party/include/"); assertThat(result.getIncludeFolder()).isEqualTo(new File("/path/to/third_party/include")); }