summaryrefslogtreecommitdiff
path: root/extensions-support/library/build.gradle
diff options
context:
space:
mode:
Diffstat (limited to 'extensions-support/library/build.gradle')
-rw-r--r--extensions-support/library/build.gradle95
1 files changed, 77 insertions, 18 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
}
}