1
+ package com.noober.plugin
2
+
3
+ import com.android.build.api.transform.Context
4
+ import com.android.build.api.transform.DirectoryInput
5
+ import com.android.build.api.transform.Format
6
+ import com.android.build.api.transform.JarInput
7
+ import com.android.build.api.transform.QualifiedContent
8
+ import com.android.build.api.transform.Transform
9
+ import com.android.build.api.transform.TransformException
10
+ import com.android.build.api.transform.TransformInput
11
+ import com.android.build.api.transform.TransformInvocation
12
+ import com.android.build.api.transform.TransformOutputProvider
13
+ import com.android.build.gradle.internal.pipeline.TransformManager
14
+ import org.apache.commons.io.FileUtils
15
+ import org.apache.commons.codec.digest.DigestUtils
16
+ import org.gradle.api.Project
17
+
18
+ public class SaveTransform extends Transform {
19
+ Project project
20
+
21
+ SaveTransform (Project project ){
22
+ this . project = project
23
+ }
24
+
25
+
26
+ @Override
27
+ String getName () {
28
+ return " MyTrans"
29
+ }
30
+
31
+ @Override
32
+ Set<QualifiedContent.ContentType > getInputTypes () {
33
+ return TransformManager . CONTENT_CLASS
34
+ }
35
+
36
+ @Override
37
+ Set<? super QualifiedContent.Scope > getScopes () {
38
+ return TransformManager . SCOPE_FULL_PROJECT
39
+ }
40
+
41
+ @Override
42
+ boolean isIncremental () {
43
+ return false
44
+ }
45
+
46
+ // @Override
47
+ // void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
48
+ // // super.transform(transformInvocation)
49
+ // transformInvocation.inputs.each { TransformInput input ->
50
+ // input.directoryInputs.each {DirectoryInput directoryInput ->
51
+ // SaveInject.inject(directoryInput.file.absolutePath, "com\\recover\\autosavesample")
52
+ //
53
+ // def filePath = transformInvocation.outputProvider.getContentLocation(directoryInput.name,
54
+ // directoryInput.scopes, Format.DIRECTORY)
55
+ // FileUtil.copy(directoryInput.file, filePath)
56
+ // }
57
+ //
58
+ // input.jarInputs.each {JarInput jarInput ->
59
+ // def jarName = jarInput.name
60
+ // def md5Name = DigestUtils.md5Hex(jarInput.file.getAbsolutePath())
61
+ // if(jarName.endsWith(".jar")) {
62
+ // jarName = jarName.substring(0,jarName.length()-4)
63
+ // }
64
+ // //生成输出路径
65
+ // def dest = outputProvider.getContentLocation(jarName+md5Name,
66
+ // jarInput.contentTypes, jarInput.scopes, Format.JAR)
67
+ // //将输入内容复制到输出
68
+ // FileUtils.copyFile(jarInput.file, dest)
69
+ // }
70
+ // }
71
+ // }
72
+
73
+ @Override
74
+ void transform (Context context , Collection<TransformInput > inputs , Collection<TransformInput > referencedInputs , TransformOutputProvider outputProvider , boolean isIncremental ) throws IOException , TransformException , InterruptedException {
75
+ inputs. each { TransformInput input ->
76
+ input. directoryInputs. each {DirectoryInput directoryInput ->
77
+ SaveInject . inject(directoryInput. file. absolutePath, " com/recover/autosavesample" , project)
78
+
79
+ def filePath = outputProvider. getContentLocation(directoryInput. name,
80
+ directoryInput. scopes, Format . DIRECTORY )
81
+ FileUtils . copy(directoryInput. file, filePath)
82
+ }
83
+
84
+ input. jarInputs. each {JarInput jarInput ->
85
+ def jarName = jarInput. name
86
+ def md5Name = DigestUtils . md5Hex(jarInput. file. getAbsolutePath())
87
+ if (jarName. endsWith(" .jar" )) {
88
+ jarName = jarName. substring(0 ,jarName. length()-4 )
89
+ }
90
+ // 生成输出路径
91
+ def dest = outputProvider. getContentLocation(jarName+ md5Name,
92
+ jarInput. contentTypes, jarInput. scopes, Format . JAR )
93
+ // 将输入内容复制到输出
94
+ FileUtils . copyFile(jarInput. file, dest)
95
+ }
96
+ }
97
+ }
98
+ }
0 commit comments