From 649d21672d3f6024179e6f4c7804545b63a08b65 Mon Sep 17 00:00:00 2001 From: Kay-Uwe Janssen Date: Thu, 27 Jul 2017 22:30:14 +0200 Subject: [PATCH 1/2] Update AndroidManifestFinder for Gradle builds with kapt --- .../helper/AndroidManifestFinder.java | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/helper/AndroidManifestFinder.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/helper/AndroidManifestFinder.java index ab0f59f35f..691bef3c35 100644 --- a/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/helper/AndroidManifestFinder.java +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/internal/helper/AndroidManifestFinder.java @@ -179,7 +179,7 @@ boolean applies() { private static class GradleAndroidManifestFinderStrategy extends AndroidManifestFinderStrategy { - static final Pattern GRADLE_GEN_FOLDER = Pattern.compile("^(.*?)build[\\\\/]generated[\\\\/]source[\\\\/]k?apt(.*)$"); + static final Pattern GRADLE_GEN_FOLDER = Pattern.compile("^(.*?)build[\\\\/]generated[\\\\/]source[\\\\/](k?apt)(.*)$"); GradleAndroidManifestFinderStrategy(String sourceFolder) { super("Gradle", GRADLE_GEN_FOLDER, sourceFolder); @@ -187,10 +187,43 @@ private static class GradleAndroidManifestFinderStrategy extends AndroidManifest @Override Iterable possibleLocations() { - String gradleVariant = matcher.group(2); + String path = matcher.group(1); + String mode = matcher.group(2); + String gradleVariant = matcher.group(3); + String variantPart = gradleVariant.substring(1); - return Arrays.asList("build/intermediates/manifests/full" + gradleVariant, "build/intermediates/bundles" + gradleVariant, - "build/intermediates/manifests/aapt" + gradleVariant); + if ("apt".equals(mode)) { + return Arrays.asList("build/intermediates/manifests/full" + gradleVariant, "build/intermediates/bundles" + gradleVariant, "build/intermediates/manifests/aapt" + gradleVariant); + } + + ArrayList possibleLocations = new ArrayList<>(); + + for (String directory : Arrays.asList("build/intermediates/manifests/full", "build/intermediates/bundles", "build/intermediates/manifests/aapt")) { + findPossibleLocations(path, directory, variantPart, possibleLocations); + } + + return possibleLocations; + } + + private void findPossibleLocations(String basePath, String targetPath, String variantPart, List possibleLocations) { + String[] directories = new File(basePath + targetPath).list(); + + if (directories == null) { + return; + } + + for (String directory : directories) { + String possibleLocation = targetPath + "/" + directory; + File variantDir = new File(basePath + possibleLocation); + if (variantDir.isDirectory() && variantPart.toLowerCase().startsWith(directory.toLowerCase())) { + String remainingPart = variantPart.substring(directory.length()); + if (remainingPart.length() == 0) { + possibleLocations.add(possibleLocation); + } else { + findPossibleLocations(basePath, possibleLocation, remainingPart, possibleLocations); + } + } + } } } From 977abb8c3876ffa024c485efe29eb5b41faa91d4 Mon Sep 17 00:00:00 2001 From: Kay-Uwe Janssen Date: Fri, 28 Jul 2017 16:05:59 +0200 Subject: [PATCH 2/2] Add tests for AndroidManifestFinder simulating the presence of a build flavor --- .../internal/helper/AndroidManifestFinderTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/internal/helper/AndroidManifestFinderTest.java b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/internal/helper/AndroidManifestFinderTest.java index a5b00cc7ec..b3d8186d5f 100644 --- a/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/internal/helper/AndroidManifestFinderTest.java +++ b/AndroidAnnotations/androidannotations-core/androidannotations/src/test/java/org/androidannotations/internal/helper/AndroidManifestFinderTest.java @@ -34,7 +34,9 @@ public class AndroidManifestFinderTest { private static final String GRADLE_GEN_FOLDER = "build/generated/source/apt/debug"; + private static final String GRADLE_FLAVOR_GEN_FOLDER = "build/generated/source/apt/flavor/debug"; private static final String GRADLE_KOTLIN_GEN_FOLDER = "build/generated/source/kapt/debug"; + private static final String GRADLE_KOTLIN_FLAVOR_GEN_FOLDER = "build/generated/source/kapt/flavorDebug"; private static final String MAVEN_GEN_FOLDER = "target/generated-sources/annotations"; @@ -58,10 +60,16 @@ public static Iterable createTestData() { Object[] gradleManifestFoundInManifests = { GRADLE_GEN_FOLDER, "build/intermediates/manifests/full/debug", true }; Object[] gradleManifestFoundInBundles = { GRADLE_GEN_FOLDER, "build/intermediates/bundles/debug", true }; Object[] gradleManifestFoundInManifestsAapt = { GRADLE_GEN_FOLDER, "build/intermediates/manifests/aapt/debug", true }; + Object[] gradleManifestFoundInManifestsWithFlavor = { GRADLE_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/full/flavor/debug", true }; + Object[] gradleManifestFoundInBundlesWithFlavor = { GRADLE_FLAVOR_GEN_FOLDER, "build/intermediates/bundles/flavor/debug", true }; + Object[] gradleManifestFoundInManifestsAaptWithFlavor = { GRADLE_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/aapt/flavor/debug", true }; Object[] gradleKotlinManifestFoundInManifests = { GRADLE_KOTLIN_GEN_FOLDER, "build/intermediates/manifests/full/debug", true }; Object[] gradleKotlinManifestFoundInBundles = { GRADLE_KOTLIN_GEN_FOLDER, "build/intermediates/bundles/debug", true }; Object[] gradleKotlinManifestFoundInManifestsAapt = { GRADLE_KOTLIN_GEN_FOLDER, "build/intermediates/manifests/aapt/debug", true }; + Object[] gradleKotlinManifestFoundInManifestsWithFlavor = { GRADLE_KOTLIN_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/full/flavor/debug", true }; + Object[] gradleKotlinManifestFoundInBundlesWithFlavor = { GRADLE_KOTLIN_FLAVOR_GEN_FOLDER, "build/intermediates/bundles/flavor/debug", true }; + Object[] gradleKotlinManifestFoundInManifestsAaptWithFlavor = { GRADLE_KOTLIN_FLAVOR_GEN_FOLDER, "build/intermediates/manifests/aapt/flavor/debug", true }; Object[] mavenManifestFoundInTarget = { MAVEN_GEN_FOLDER, "target", true }; Object[] mavenManifestFoundInSrc = { MAVEN_GEN_FOLDER, "src/main", true }; @@ -80,7 +88,9 @@ public static Iterable createTestData() { Object[] noGeneratedFolderFound = { "", "", false }; return Arrays.asList(gradleManifestFoundInManifests, gradleManifestFoundInBundles, gradleManifestFoundInManifestsAapt, + gradleManifestFoundInManifestsWithFlavor, gradleManifestFoundInBundlesWithFlavor, gradleManifestFoundInManifestsAaptWithFlavor, gradleKotlinManifestFoundInManifests, gradleKotlinManifestFoundInBundles, gradleKotlinManifestFoundInManifestsAapt, + gradleKotlinManifestFoundInManifestsWithFlavor, gradleKotlinManifestFoundInBundlesWithFlavor, gradleKotlinManifestFoundInManifestsAaptWithFlavor, mavenManifestFoundInTarget, mavenManifestFoundInSrc, mavenManifestFoundInRoot, eclipseManifestFound, gradleManifestNotFound, gradleKotlinManifestNotFound, mavenManifestNotFound, eclipseManifestNotFound, noGeneratedFolderFound);