From 918227afed60272e80fcf9c95e79e4a384c16a49 Mon Sep 17 00:00:00 2001 From: Kay-Uwe Janssen Date: Thu, 30 May 2019 15:09:36 +0200 Subject: [PATCH 1/4] Remove unnecessary throws declaration (cherry picked from commit 1c48970ade71852c8a3e305641ef88a105d35f2d) --- .../internal/helper/AndroidManifestFinder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f1239fd10e..9a7c9092b5 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 @@ -126,7 +126,7 @@ private File findManifestInKnownPaths() throws FileNotFoundException { return findManifestInKnownPathsStartingFromGenFolder(holder.sourcesGenerationFolder.getAbsolutePath()); } - File findManifestInKnownPathsStartingFromGenFolder(String sourcesGenerationFolder) throws FileNotFoundException { + File findManifestInKnownPathsStartingFromGenFolder(String sourcesGenerationFolder) { Iterable strategies = Arrays.asList(new GradleAndroidManifestFinderStrategy(environment, sourcesGenerationFolder), new MavenAndroidManifestFinderStrategy(sourcesGenerationFolder), new EclipseAndroidManifestFinderStrategy(sourcesGenerationFolder)); From b26727947777f146c6de3505e455e8d7b54f37ba Mon Sep 17 00:00:00 2001 From: Kay-Uwe Janssen Date: Thu, 30 May 2019 16:11:02 +0200 Subject: [PATCH 2/4] Rename local variable `matcher` to not shadow field (cherry picked from commit c7bc0b574234c537b4f976df35d215eba8b7f9a0) --- .../internal/helper/AndroidManifestFinder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 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 9a7c9092b5..7f75229cd5 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 @@ -220,9 +220,9 @@ private List updateLocations(String path, List possibleLocations String expectedLocation = path + "/" + location; File file = new File(expectedLocation + "/output.json"); if (file.exists()) { - Matcher matcher = OUTPUT_JSON_PATTERN.matcher(readJsonFromFile(file)); - if (matcher.matches()) { - String relativeManifestPath = matcher.group(1); + Matcher jsonMatcher = OUTPUT_JSON_PATTERN.matcher(readJsonFromFile(file)); + if (jsonMatcher.matches()) { + String relativeManifestPath = jsonMatcher.group(1); File manifestFile = new File(expectedLocation + "/" + relativeManifestPath); String manifestDirectory = manifestFile.getParentFile().getAbsolutePath(); knownLocations.add(manifestDirectory.substring(path.length())); From 68b18b226a6c09e91c8a3e3802c474c19e680115 Mon Sep 17 00:00:00 2001 From: Kay-Uwe Janssen Date: Thu, 30 May 2019 16:14:58 +0200 Subject: [PATCH 3/4] Support Android Gradle Plugin 3.5.0-beta03 and 3.6.0-alpha01 (cherry picked from commit de366e34d77424c95be0ddce1e1e1fdd4c70bbd7) --- .../helper/AndroidManifestFinder.java | 54 +++++++++++++++---- 1 file changed, 43 insertions(+), 11 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 7f75229cd5..5dd611bda4 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 @@ -128,7 +128,8 @@ private File findManifestInKnownPaths() throws FileNotFoundException { File findManifestInKnownPathsStartingFromGenFolder(String sourcesGenerationFolder) { Iterable strategies = Arrays.asList(new GradleAndroidManifestFinderStrategy(environment, sourcesGenerationFolder), - new MavenAndroidManifestFinderStrategy(sourcesGenerationFolder), new EclipseAndroidManifestFinderStrategy(sourcesGenerationFolder)); + new LegacyGradleAndroidManifestFinderStrategy(environment, sourcesGenerationFolder), new MavenAndroidManifestFinderStrategy(sourcesGenerationFolder), + new EclipseAndroidManifestFinderStrategy(sourcesGenerationFolder)); AndroidManifestFinderStrategy applyingStrategy = null; @@ -181,9 +182,36 @@ boolean applies() { abstract Iterable possibleLocations(); } - private static class GradleAndroidManifestFinderStrategy extends AndroidManifestFinderStrategy { + private static class GradleAndroidManifestFinderStrategy extends AbstractGradleAndroidManifestFinderStrategy { + + private static final Pattern GRADLE_GEN_FOLDER = Pattern.compile("^(.*?)build[\\\\/]generated[\\\\/]ap_generated_sources[\\\\/](.*)[\\\\/]out(.*)$"); + + GradleAndroidManifestFinderStrategy(AndroidAnnotationsEnvironment environment, String sourceFolder) { + super(GRADLE_GEN_FOLDER, environment, sourceFolder); + } + + @Override + protected String getGradleVariant() { + return matcher.group(2); + } + } + + private static class LegacyGradleAndroidManifestFinderStrategy extends AbstractGradleAndroidManifestFinderStrategy { + + private static final Pattern GRADLE_GEN_FOLDER = Pattern.compile("^(.*?)build[\\\\/]generated[\\\\/]source[\\\\/](k?apt)(.*)$"); + + LegacyGradleAndroidManifestFinderStrategy(AndroidAnnotationsEnvironment environment, String sourceFolder) { + super(GRADLE_GEN_FOLDER, environment, sourceFolder); + } + + @Override + protected String getGradleVariant() { + return matcher.group(3).substring(1); + } + } + + private static abstract class AbstractGradleAndroidManifestFinderStrategy extends AndroidManifestFinderStrategy { - static final Pattern GRADLE_GEN_FOLDER = Pattern.compile("^(.*?)build[\\\\/]generated[\\\\/]source[\\\\/](k?apt)(.*)$"); static final Pattern OUTPUT_JSON_PATTERN = Pattern.compile(".*,\"path\":\"(.*?)\",.*"); private static final List SUPPORTED_ABI_SPLITS = Arrays.asList("arm64-v8a", "armeabi", "armeabi-v7a", "mips", "mips64", "x86", "x86_64"); @@ -193,22 +221,26 @@ private static class GradleAndroidManifestFinderStrategy extends AndroidManifest private final AndroidAnnotationsEnvironment environment; - GradleAndroidManifestFinderStrategy(AndroidAnnotationsEnvironment environment, String sourceFolder) { - super("Gradle", GRADLE_GEN_FOLDER, sourceFolder); + AbstractGradleAndroidManifestFinderStrategy(Pattern pattern, AndroidAnnotationsEnvironment environment, String sourceFolder) { + super("Gradle", pattern, sourceFolder); this.environment = environment; } + protected String getPath() { + return matcher.group(1); + } + + protected abstract String getGradleVariant(); + @Override Iterable possibleLocations() { - String path = matcher.group(1); - String mode = matcher.group(2); - String gradleVariant = matcher.group(3); - String variantPart = gradleVariant.substring(1); + String path = getPath(); + String gradleVariant = getGradleVariant(); List possibleLocations = new ArrayList<>(); - findPossibleLocationsV32(path, variantPart, possibleLocations); + findPossibleLocationsV32(path, gradleVariant, possibleLocations); for (String directory : Arrays.asList("build/intermediates/manifests/full", "build/intermediates/bundles", "build/intermediates/manifests/aapt")) { - findPossibleLocations(path, directory, variantPart, possibleLocations); + findPossibleLocations(path, directory, gradleVariant, possibleLocations); } return updateLocations(path, possibleLocations); From 7d01ae80d3765a128db58f9a21d1b0c7c503ee2a Mon Sep 17 00:00:00 2001 From: Kay-Uwe Janssen Date: Thu, 30 May 2019 16:16:08 +0200 Subject: [PATCH 4/4] Update AndroidManifestFinderTEst (cherry picked from commit 754a09a69f9740695dadb7900113ba1e98a9f7dc) --- .../helper/AndroidManifestFinderTest.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) 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 7ebfdb5d19..45be83c79f 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 @@ -90,6 +90,17 @@ public static Iterable createTestData() { Object[] gradleManifestFoundInMergedManifestsWithBothSplitV33 = { GRADLE_GEN_FOLDER, "build/intermediates/merged_manifests/debug/x86/hdpi", true }; Object[] gradleManifestFoundInMergedManifestsWithBothSplitAndFlavorV33 = { GRADLE_FLAVOR_GEN_FOLDER, "build/intermediates/merged_manifests/flavorDebug/x86/hdpi", true }; + Object[] gradleManifestFoundInMergedManifestsV35 = { "build/generated/ap_generated_sources/debug/out", "build/intermediates/merged_manifests/debug/", true }; + Object[] gradleManifestFoundInMergedManifestsWithAbiSplitV35 = { "build/generated/ap_generated_sources/debug/out", "build/intermediates/merged_manifests/debug/x86", true }; + Object[] gradleManifestFoundInMergedManifestsWithAbiSplitAndFlavorV35 = { "build/generated/ap_generated_sources/flavorDebug/out", "build/intermediates/merged_manifests/flavorDebug/x86", + true }; + Object[] gradleManifestFoundInMergedManifestsWithDensitySplitV35 = { "build/generated/ap_generated_sources/debug/out", "build/intermediates/merged_manifests/debug/hdpi", true }; + Object[] gradleManifestFoundInMergedManifestsWithDensitySplitAndFlavorV35 = { "build/generated/ap_generated_sources/flavorDebug/out", "build/intermediates/merged_manifests/flavorDebug/hdpi", + true }; + Object[] gradleManifestFoundInMergedManifestsWithBothSplitV35 = { "build/generated/ap_generated_sources/debug/out", "build/intermediates/merged_manifests/debug/x86/hdpi", true }; + Object[] gradleManifestFoundInMergedManifestsWithBothSplitAndFlavorV35 = { "build/generated/ap_generated_sources/flavorDebug/out", "build/intermediates/merged_manifests/flavorDebug/x86/hdpi", + 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 }; @@ -145,17 +156,19 @@ public static Iterable createTestData() { gradleManifestFoundInMergedManifestsWithBothSplit, gradleManifestFoundInMergedManifestsWithBothSplitAndFlavor, gradleManifestFoundInMergedManifestsV33, gradleManifestFoundInMergedManifestsWithAbiSplitV33, gradleManifestFoundInMergedManifestsWithAbiSplitAndFlavorV33, gradleManifestFoundInMergedManifestsWithDensitySplitV33, gradleManifestFoundInMergedManifestsWithDensitySplitAndFlavorV33, gradleManifestFoundInMergedManifestsWithBothSplitV33, gradleManifestFoundInMergedManifestsWithBothSplitAndFlavorV33, - gradleKotlinManifestFoundInManifests, gradleKotlinManifestFoundInBundles, gradleKotlinManifestFoundInManifestsAapt, gradleKotlinManifestFoundInManifestsWithFlavor, - gradleKotlinManifestFoundInBundlesWithFlavor, gradleKotlinManifestFoundInManifestsAaptWithFlavor, gradleKotlinManifestFoundInManifestsWithAbiSplit, - gradleKotlinManifestFoundInManifestsWithAbiSplitAndFlavor, gradleKotlinManifestFoundInManifestsWithDensitySplit, gradleKotlinManifestFoundInManifestsWithDensitySplitAndFlavor, - gradleKotlinManifestFoundInManifestsWithBothSplit, gradleKotlinManifestFoundInManifestsWithBothSplitAndFlavor, gradleKotlinManifestFoundInMergedManifests, - gradleKotlinManifestFoundInMergedManifestsWithAbiSplit, gradleKotlinManifestFoundInMergedManifestsWithAbiSplitAndFlavor, gradleKotlinManifestFoundInMergedManifestsWithDensitySplit, - gradleKotlinManifestFoundInMergedManifestsWithDensitySplitAndFlavor, gradleKotlinManifestFoundInMergedManifestsWithBothSplit, - gradleKotlinManifestFoundInMergedManifestsWithBothSplitAndFlavor, gradleKotlinManifestFoundInMergedManifestsV33, gradleKotlinManifestFoundInMergedManifestsWithAbiSplitV33, - gradleKotlinManifestFoundInMergedManifestsWithAbiSplitAndFlavorV33, gradleKotlinManifestFoundInMergedManifestsWithDensitySplitV33, - gradleKotlinManifestFoundInMergedManifestsWithDensitySplitAndFlavorV33, gradleKotlinManifestFoundInMergedManifestsWithBothSplitV33, - gradleKotlinManifestFoundInMergedManifestsWithBothSplitAndFlavorV33, mavenManifestFoundInTarget, mavenManifestFoundInSrc, mavenManifestFoundInRoot, eclipseManifestFound, - gradleManifestNotFound, gradleKotlinManifestNotFound, mavenManifestNotFound, eclipseManifestNotFound, noGeneratedFolderFound); + gradleManifestFoundInMergedManifestsV35, gradleManifestFoundInMergedManifestsWithAbiSplitV35, gradleManifestFoundInMergedManifestsWithAbiSplitAndFlavorV35, + gradleManifestFoundInMergedManifestsWithDensitySplitV35, gradleManifestFoundInMergedManifestsWithDensitySplitAndFlavorV35, gradleManifestFoundInMergedManifestsWithBothSplitV35, + gradleManifestFoundInMergedManifestsWithBothSplitAndFlavorV35, gradleKotlinManifestFoundInManifests, gradleKotlinManifestFoundInBundles, gradleKotlinManifestFoundInManifestsAapt, + gradleKotlinManifestFoundInManifestsWithFlavor, gradleKotlinManifestFoundInBundlesWithFlavor, gradleKotlinManifestFoundInManifestsAaptWithFlavor, + gradleKotlinManifestFoundInManifestsWithAbiSplit, gradleKotlinManifestFoundInManifestsWithAbiSplitAndFlavor, gradleKotlinManifestFoundInManifestsWithDensitySplit, + gradleKotlinManifestFoundInManifestsWithDensitySplitAndFlavor, gradleKotlinManifestFoundInManifestsWithBothSplit, gradleKotlinManifestFoundInManifestsWithBothSplitAndFlavor, + gradleKotlinManifestFoundInMergedManifests, gradleKotlinManifestFoundInMergedManifestsWithAbiSplit, gradleKotlinManifestFoundInMergedManifestsWithAbiSplitAndFlavor, + gradleKotlinManifestFoundInMergedManifestsWithDensitySplit, gradleKotlinManifestFoundInMergedManifestsWithDensitySplitAndFlavor, + gradleKotlinManifestFoundInMergedManifestsWithBothSplit, gradleKotlinManifestFoundInMergedManifestsWithBothSplitAndFlavor, gradleKotlinManifestFoundInMergedManifestsV33, + gradleKotlinManifestFoundInMergedManifestsWithAbiSplitV33, gradleKotlinManifestFoundInMergedManifestsWithAbiSplitAndFlavorV33, + gradleKotlinManifestFoundInMergedManifestsWithDensitySplitV33, gradleKotlinManifestFoundInMergedManifestsWithDensitySplitAndFlavorV33, + gradleKotlinManifestFoundInMergedManifestsWithBothSplitV33, gradleKotlinManifestFoundInMergedManifestsWithBothSplitAndFlavorV33, mavenManifestFoundInTarget, mavenManifestFoundInSrc, + mavenManifestFoundInRoot, eclipseManifestFound, gradleManifestNotFound, gradleKotlinManifestNotFound, mavenManifestNotFound, eclipseManifestNotFound, noGeneratedFolderFound); } @Test