-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Android source sets (#327)
* Add support for Android source sets * optionalPlugins configuration naming correction * Code consolidation * Encapsulate android source set parsing in separate classes * Add missing copyrights. Remove dead code * Include test variants. Remove redundant AndroidProjectSpec * Support for AGP versions 3.x * Add AGP 3.* test * Revert unrelated auto-formatting * Correct regressions parsing multi-project repos * Set progress bar callback when parsing Java/Kotlin source sets * Fix JacksonXML version to 2.17.2 * Disable AGP 3 test on gradle versions less than 8 * Enable AGP 3 test on gradle versions less than 8 * Fix AGP 3 test for :plugin:testGradle4 * Add runtime dependencies collection. Add test demonstrating that the same java source files are parsed twice * Prevent repeated parsing of androud source files found in multiple variants * Annotate static fields with @nullable --------- Co-authored-by: Sam Snyder <[email protected]>
- Loading branch information
1 parent
3679f30
commit 8139f0e
Showing
10 changed files
with
1,207 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
plugin/src/main/java/org/openrewrite/gradle/isolated/AndroidProjectCompileOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openrewrite.gradle.isolated; | ||
|
||
import com.android.build.gradle.BaseExtension; | ||
import org.gradle.api.JavaVersion; | ||
|
||
import java.lang.reflect.Method; | ||
import java.nio.charset.Charset; | ||
|
||
/* | ||
* AGP versions less than 4 define CompileOptions in com.android.build.gradle.internal.CompileOptions where as | ||
* versions greater than 4 define it in com.android.build.api.dsl.CompileOptions. This class encapsulates fetching | ||
* CompileOptions using either type. | ||
*/ | ||
class AndroidProjectCompileOptions { | ||
private final Charset encoding; | ||
private final String sourceCompatibility; | ||
private final String targetCompatibility; | ||
|
||
AndroidProjectCompileOptions(Charset encoding, String sourceCompatibility, String targetCompatibility) { | ||
this.encoding = encoding; | ||
this.sourceCompatibility = sourceCompatibility; | ||
this.targetCompatibility = targetCompatibility; | ||
} | ||
|
||
static AndroidProjectCompileOptions fromBaseExtension(BaseExtension baseExtension) throws ReflectiveOperationException { | ||
Object compileOptions = callMethod(baseExtension, "getCompileOptions"); | ||
String fileEncoding = callMethod(compileOptions, "getEncoding"); | ||
JavaVersion sourceCompatibilityVersion = callMethod(compileOptions, "getSourceCompatibility"); | ||
JavaVersion targetCompatibilityVersion = callMethod(compileOptions, "getTargetCompatibility"); | ||
return new AndroidProjectCompileOptions( | ||
Charset.forName(fileEncoding), | ||
sourceCompatibilityVersion.toString(), | ||
targetCompatibilityVersion.toString()); | ||
} | ||
|
||
private static <T> T callMethod(Object obj, String methodName) throws ReflectiveOperationException { | ||
Method method = obj.getClass().getMethod(methodName); | ||
return (T) method.invoke(obj); | ||
} | ||
|
||
Charset getEncoding() { | ||
return encoding; | ||
} | ||
|
||
String getSourceCompatibility() { | ||
return sourceCompatibility; | ||
} | ||
|
||
String getTargetCompatibility() { | ||
return targetCompatibility; | ||
} | ||
} |
Oops, something went wrong.