Skip to content

Commit 3b27194

Browse files
author
wangfeihang
committed
先随便写写满足基本功能
1 parent 1f6bab4 commit 3b27194

6 files changed

Lines changed: 331 additions & 114 deletions

File tree

localrepo/build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,15 @@ dependencies {
88
compile localGroovy()
99
}
1010

11-
version='1.0.0'
11+
version='1.0.1'
12+
13+
//
14+
//group='com.yy.localrepo'
15+
//
16+
//uploadArchives {
17+
// repositories {
18+
// mavenDeployer {
19+
// repository(url: uri('../pluginrepo'))
20+
// }
21+
// }
22+
//}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.yy.localrepo
2+
3+
import org.gradle.api.Project
4+
import org.gradle.api.artifacts.Dependency
5+
import org.gradle.api.artifacts.ResolvedDependency
6+
7+
import javax.print.DocFlavor.STRING
8+
9+
/**
10+
* Created by wangfeihang on 2018/10/19.
11+
*/
12+
public class CopyDependency {
13+
14+
def static copyDependencies(Dependency dependency, Project project, String repo,Closure dontCopy) {
15+
def dependencyPath = project.gradle.getGradleUserHomeDir().path + "/caches/modules-2/files-2.1/"
16+
dependencyPath += dependency.group + "/" + dependency.name + "/" + dependency.version + "/"
17+
18+
def libsPath = "$repo${File.separator}libs"
19+
project.fileTree(dependencyPath).getFiles().each { file ->
20+
copyFile(file, project, libsPath,dontCopy)
21+
}
22+
}
23+
24+
def static copyDependencies(ResolvedDependency dependency, Project project, String repo,Closure dontCopy) {
25+
def libsPath = "$repo${File.separator}libs"
26+
dependency.getModuleArtifacts().each { resolvedArtifact ->
27+
copyFile(resolvedArtifact.file, project, libsPath,dontCopy)
28+
}
29+
}
30+
31+
private static void copyFile(File file, Project project, String libsPath,Closure dontCopy) {
32+
if (file.name.contains("sources")||dontCopy.call(file.name)) {
33+
return
34+
}
35+
if (file.name.endsWith(".aar")) {
36+
project.copy {
37+
from file.path
38+
into project.file(libsPath)
39+
}
40+
} else if (file.name.endsWith(".jar")) {
41+
project.copy {
42+
from file.path
43+
into project.file(libsPath)
44+
}
45+
} else if (file.name.endsWith(".so")) {
46+
project.copy {
47+
from file.path
48+
into project.file("${libsPath}/armeabi-v7a")
49+
exclude("*x86.so")
50+
exclude("*armeabi.so")
51+
}
52+
}
53+
}
54+
55+
56+
def static ArrayList<NodeAdder.PomNode> getInnerDependencies(Dependency dependency, Project project, Closure isLocal, String repo,Closure dontCopy){
57+
def repoNodeResults=new ArrayList()
58+
def dependencyPath = project.gradle.getGradleUserHomeDir().path + "/caches/modules-2/files-2.1/"
59+
dependencyPath += dependency.group + "/" + dependency.name + "/" + dependency.version + "/"
60+
61+
def libsPath = "$repo${File.separator}libs"
62+
project.fileTree(dependencyPath).getFiles().each { file ->
63+
if(file.name.endsWith(".pom")){
64+
processPomFile(file.path,project,repoNodeResults,isLocal,libsPath,dontCopy)
65+
}
66+
}
67+
return repoNodeResults
68+
}
69+
70+
71+
def private static processPomFile(String pomPath, Project project, ArrayList<NodeAdder.PomNode> repoNodes, Closure isLocal, String libsPath,Closure dontCopy) {
72+
def pom = new XmlSlurper().parse(new File(pomPath))
73+
pom.dependencies.children().each {
74+
def subJarLocation = project.gradle.getGradleUserHomeDir().path + "/caches/modules-2/files-2.1/"
75+
if (!it.scope.text().equals("test") && !it.scope.text().equals("provided")) {
76+
String version = it.version.text()
77+
if (version.startsWith("\${") && version.endsWith("}")) {
78+
pom.properties.children().each {
79+
if (version.contains(it.name())) {
80+
version = it.text()
81+
}
82+
}
83+
}
84+
85+
subJarLocation += it.groupId.text() + "/" + it.artifactId.text() + "/" + version + "/"
86+
def islocal=isLocal.call("${it.groupId.text()}:${it.artifactId.text()}:${version}")
87+
if(!islocal && version!=null&&!version.isEmpty()&&!it.artifactId.text().contains("animal-sniffer-annotations")&&!it.artifactId.text().contains("kotlin")&&!it.artifactId.text().contains("jetbrains")&&!it.groupId.text().contains("kotlin")&&!it.groupId.text().contains("jetbrains")){
88+
repoNodes.add(new NodeAdder.PomNode(it.groupId.text(),it.artifactId.text(),version))
89+
// repoNodes.add(it)
90+
}else if(islocal){
91+
project.fileTree(subJarLocation).getFiles().each { file ->
92+
if (file.name.endsWith(".pom")) {
93+
processPomFile(file.path,project,repoNodes,isLocal,libsPath,dontCopy)
94+
} else if(islocal){
95+
if (!file.name.contains("sources")) {
96+
copyFile(file, project, libsPath,dontCopy)
97+
}
98+
}
99+
}
100+
}
101+
}
102+
}
103+
}
104+
105+
106+
}

0 commit comments

Comments
 (0)