Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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