From d42740d1fabbd943448513a355537cfe397b7a11 Mon Sep 17 00:00:00 2001 From: LaurieScheepers Date: Sun, 6 Sep 2020 13:33:07 +0200 Subject: [PATCH] Add support for Windows. See https://github.com/alexzaitsev/apk-dependency-graph/issues/60 for an explanation. Fixed unit test. --- build.gradle | 7 ++++--- gradle/wrapper/gradle-wrapper.properties | 3 ++- .../com/alex_zaitsev/adg/FilterProvider.java | 18 ++++++++---------- src/test/java/FilterProviderTests.java | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 6b11e29..7e1e404 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,8 @@ clean { delete = ['build'] } dependencies { - implementation 'org.smali:baksmali:2.2.5' // runtime dependency - testImplementation 'org.hamcrest:hamcrest:2.1' // test dependency - testImplementation 'junit:junit:4.12' // test dependency + implementation 'org.smali:baksmali:2.2.5' // runtime dependency + testImplementation 'org.hamcrest:hamcrest:2.1' // test dependency + testImplementation 'junit:junit:4.12' // test dependency + implementation 'org.apache.commons:commons-lang3:3.11' // used to determine OS } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 44e7c4d..2d120bc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Sun Sep 06 11:58:44 CAT 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip diff --git a/src/main/java/com/alex_zaitsev/adg/FilterProvider.java b/src/main/java/com/alex_zaitsev/adg/FilterProvider.java index 2d9403e..963d353 100644 --- a/src/main/java/com/alex_zaitsev/adg/FilterProvider.java +++ b/src/main/java/com/alex_zaitsev/adg/FilterProvider.java @@ -3,6 +3,8 @@ import com.alex_zaitsev.adg.io.*; import com.alex_zaitsev.adg.filter.*; +import org.apache.commons.lang3.SystemUtils; + import java.io.File; import java.util.regex.Matcher; @@ -17,21 +19,17 @@ public FilterProvider(Filters inputFilters) { public Filter makePathFilter() { String replacement = Matcher.quoteReplacement(File.separator); replacement = Matcher.quoteReplacement(replacement); - String packageNameAsPath = inputFilters.getPackageName().replaceAll("\\.", replacement); + + // see https://github.com/alexzaitsev/apk-dependency-graph/issues/60 + String packageNameAsPath = inputFilters.getPackageName().replaceAll(SystemUtils.IS_OS_WINDOWS ? "/" : "\\.", replacement); String packageNameRegex = ".*" + packageNameAsPath + ".*"; - RegexFilter filter = new RegexFilter(packageNameRegex); - - return filter; + + return new RegexFilter(packageNameRegex); } public Filter makeClassFilter() { String[] ignoredClasses = inputFilters.getIgnoredClasses(); - if (ignoredClasses == null) { - return null; - } - - InverseRegexFilter ignoredClassesFilter = new InverseRegexFilter(ignoredClasses); - return ignoredClassesFilter; + return ignoredClasses == null ? null : new InverseRegexFilter(ignoredClasses); } } \ No newline at end of file diff --git a/src/test/java/FilterProviderTests.java b/src/test/java/FilterProviderTests.java index 27dff59..6379962 100644 --- a/src/test/java/FilterProviderTests.java +++ b/src/test/java/FilterProviderTests.java @@ -36,7 +36,7 @@ public void makePathFilterReturnsExpectedFilter() { assertThat(filter, notNullValue()); String filterStringRepr = File.separatorChar == '/' ? "RegexFilter{.*com/example/package.*}" : // for Unix - "RegexFilter{.*com\\\\example\\\\package.*}"; // for Windows + "RegexFilter{.*com.example.package.*}"; // for Windows assertThat(filter.toString(), equalTo(filterStringRepr)); }