summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Dochez <jedo@google.com>2022-10-21 11:30:16 -0700
committerJerome Dochez <jedo@google.com>2022-11-14 19:34:35 +0000
commit69aab8c10428ff5664c10af44e5b6ed67b28a769 (patch)
tree82d78f25d3e670389e13c02e279452cd21506a8c
parent660cf32bb26095700d80d5a11a0ec129c98decf1 (diff)
downloaddata-binding-69aab8c10428ff5664c10af44e5b6ed67b28a769.tar.gz
stop using a deprecated API.
The extensions-support was still using a deprecated API that never graduated to stable. Replaced it with the newer API that is now stable. Test: existing Bug: N/A Change-Id: I9198cf772ed0a63fd6649435d7a882da3dd3a8fc
-rw-r--r--extensions-support/library/build.gradle95
-rw-r--r--extensions/library/build.gradle94
2 files changed, 153 insertions, 36 deletions
diff --git a/extensions-support/library/build.gradle b/extensions-support/library/build.gradle
index 38abde26..d933b552 100644
--- a/extensions-support/library/build.gradle
+++ b/extensions-support/library/build.gradle
@@ -14,6 +14,11 @@
* limitations under the License.
*/
import com.android.build.api.artifact.MultipleArtifact;
+import com.android.build.api.artifact.ScopedArtifact;
+import com.android.build.api.variant.ScopedArtifacts;
+import java.util.jar.*;
+import java.util.regex.*;
+
// Top-level build file where you can add dataBindingConfiguration options common to all sub-projects/modules.
apply plugin: 'com.android.library'
@@ -54,9 +59,21 @@ android {
TaskProvider<ExcludeShimsTask> taskProvider = project.tasks.register(
variant.getName() + "ExcludeShimsTask", ExcludeShimsTask.class
)
- variant.artifacts.use(taskProvider)
- .wiredWith( { it.getAllClasses() }, { it.getOutput() })
- .toTransform(MultipleArtifact.ALL_CLASSES_DIRS.INSTANCE)
+
+ variant.artifacts
+ .forScope(ScopedArtifacts.Scope.PROJECT)
+ .use(taskProvider)
+ .toTransform(
+ ScopedArtifact.CLASSES.INSTANCE,
+ { it.getAllJars() },
+ { it.getAllDirectories() },
+ { it.getOutput() }
+ )
+
+ taskProvider.configure { task ->
+ task.excludes.add("android/databinding/DataBindingComponent.*")
+ task.excludes.add("android/databinding/DataBinderMapperImpl.*")
+ }
})
}
@@ -112,27 +129,69 @@ afterEvaluate {
/**
* Remove shim classes that will be generated by the application annotation processor.
*/
-abstract class ExcludeShimsTask extends DefaultTask {
+abstract class ExcludeShimsTask extends Jar {
+ @InputFiles
+ abstract ListProperty<RegularFile> getAllJars();
+
@InputFiles
- abstract ListProperty<Directory> getAllClasses();
+ abstract ListProperty<Directory> getAllDirectories();
- @OutputDirectory
- abstract DirectoryProperty getOutput();
+ @OutputFiles
+ abstract RegularFileProperty getOutput();
+
+ @Input
+ Set<String> excludes = new HashSet<String>();
@TaskAction
- def excludeShimClasses() {
- File outputDir = output.get().asFile
- outputDir.delete();
- outputDir.mkdirs();
-
- allClasses.get().forEach { directory ->
- project.copy {
- from directory
- into output
- exclude 'android/databinding/DataBindingComponent.*'
- exclude 'android/databinding/DataBinderMapperImpl.*'
+ void taskAction() {
+
+ OutputStream jarOutput = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(
+ output.get().getAsFile()
+ )))
+
+ Set<Pattern> patterns = excludes.collect {
+ Pattern.compile(it)
+ }
+
+ allJars.get().forEach { file ->
+ JarFile jarFile = new JarFile(file.asFile)
+ for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) {
+ JarEntry jarEntry = e.nextElement();
+ if (!shouldIgnore(patterns, jarEntry.name)) {
+ jarOutput.putNextEntry(new JarEntry(jarEntry.name))
+ jarFile.getInputStream(jarEntry).withCloseable {
+ jarOutput << it
+ }
+ jarOutput.closeEntry()
+ }
+ }
+ jarFile.close()
+ }
+
+ allDirectories.get().forEach { directory ->
+ directory.asFile.traverse(type: groovy.io.FileType.FILES) { file ->
+ String relativePath = directory.asFile.toURI().relativize(file.toURI()).getPath()
+ .replace(File.separatorChar, '/' as char)
+
+ if (!shouldIgnore(patterns, relativePath)) {
+ jarOutput.putNextEntry(new JarEntry(relativePath))
+ new FileInputStream(file).withCloseable { inputStream ->
+ jarOutput << inputStream
+ }
+ jarOutput.closeEntry()
+ }
+ }
+ }
+ jarOutput.close()
+ }
+
+ boolean shouldIgnore(Collection<Pattern> patterns, String entryName) {
+ for (pattern in patterns) {
+ if (pattern.matcher(entryName).matches()) {
+ return true
}
}
+ return false
}
}
diff --git a/extensions/library/build.gradle b/extensions/library/build.gradle
index 13a50f66..e9a02bb5 100644
--- a/extensions/library/build.gradle
+++ b/extensions/library/build.gradle
@@ -14,6 +14,10 @@
* limitations under the License.
*/
import com.android.build.api.artifact.MultipleArtifact;
+import com.android.build.api.artifact.ScopedArtifact;
+import com.android.build.api.variant.ScopedArtifacts;
+import java.util.jar.*;
+import java.util.regex.*;
apply plugin: 'com.android.library'
@@ -53,9 +57,21 @@ android {
TaskProvider<ExcludeShimsTask> taskProvider = project.tasks.register(
variant.getName() + "ExcludeShimsTask", ExcludeShimsTask.class
)
- variant.artifacts.use(taskProvider)
- .wiredWith( { it.getAllClasses() }, { it.getOutput() })
- .toTransform(MultipleArtifact.ALL_CLASSES_DIRS.INSTANCE)
+
+ variant.artifacts
+ .forScope(ScopedArtifacts.Scope.PROJECT)
+ .use(taskProvider)
+ .toTransform(
+ ScopedArtifact.CLASSES.INSTANCE,
+ { it.getAllJars() },
+ { it.getAllDirectories() },
+ { it.getOutput() }
+ )
+
+ taskProvider.configure { task ->
+ task.excludes.add("androidx/databinding/DataBindingComponent.*")
+ task.excludes.add("androidx/databinding/DataBinderMapperImpl.*")
+ }
})
}
@@ -113,27 +129,69 @@ afterEvaluate {
/**
* Remove shim classes that will be generated by the application annotation processor.
*/
-abstract class ExcludeShimsTask extends DefaultTask {
+abstract class ExcludeShimsTask extends Jar {
@InputFiles
- abstract ListProperty<Directory> getAllClasses();
+ abstract ListProperty<RegularFile> getAllJars();
+
+ @InputFiles
+ abstract ListProperty<Directory> getAllDirectories();
+
+ @OutputFiles
+ abstract RegularFileProperty getOutput();
- @OutputDirectory
- abstract DirectoryProperty getOutput();
+ @Input
+ Set<String> excludes = new HashSet<String>();
@TaskAction
- def excludeShimClasses() {
- File outputDir = output.get().asFile
- outputDir.delete();
- outputDir.mkdirs();
-
- allClasses.get().forEach { directory ->
- project.copy {
- from directory
- into output
- exclude 'androidx/databinding/DataBindingComponent.*'
- exclude 'androidx/databinding/DataBinderMapperImpl.*'
+ void taskAction() {
+
+ OutputStream jarOutput = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(
+ output.get().getAsFile()
+ )))
+
+ Set<Pattern> patterns = excludes.collect {
+ Pattern.compile(it)
+ }
+
+ allJars.get().forEach { file ->
+ JarFile jarFile = new JarFile(file.asFile)
+ for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) {
+ JarEntry jarEntry = e.nextElement();
+ if (!shouldIgnore(patterns, jarEntry.name)) {
+ jarOutput.putNextEntry(new JarEntry(jarEntry.name))
+ jarFile.getInputStream(jarEntry).withCloseable {
+ jarOutput << it
+ }
+ jarOutput.closeEntry()
+ }
+ }
+ jarFile.close()
+ }
+
+ allDirectories.get().forEach { directory ->
+ directory.asFile.traverse(type: groovy.io.FileType.FILES) { file ->
+ String relativePath = directory.asFile.toURI().relativize(file.toURI()).getPath()
+ .replace(File.separatorChar, '/' as char)
+
+ if (!shouldIgnore(patterns, relativePath)) {
+ jarOutput.putNextEntry(new JarEntry(relativePath))
+ new FileInputStream(file).withCloseable { inputStream ->
+ jarOutput << inputStream
+ }
+ jarOutput.closeEntry()
+ }
+ }
+ }
+ jarOutput.close()
+ }
+
+ boolean shouldIgnore(Collection<Pattern> patterns, String entryName) {
+ for (pattern in patterns) {
+ if (pattern.matcher(entryName).matches()) {
+ return true
}
}
+ return false
}
}