Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2030 from dodgex/2028_improve_manifestfinder_for_…
Browse files Browse the repository at this point in the history
…kapt_with_variants

Update AndroidManifestFinder for Gradle builds with kapt
  • Loading branch information
WonderCsabo committed Jul 30, 2017
2 parents 3978dfe + 977abb8 commit ffbffe1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Expand Up @@ -179,18 +179,51 @@ 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);
}

@Override
Iterable<String> 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<String> 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<String> 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);
}
}
}
}
}

Expand Down
Expand Up @@ -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";

Expand All @@ -58,10 +60,16 @@ public static Iterable<Object[]> 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 };
Expand All @@ -80,7 +88,9 @@ public static Iterable<Object[]> 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);
Expand Down

0 comments on commit ffbffe1

Please sign in to comment.