This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
121 lines (99 loc) · 4.2 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
plugins {
id 'java'
id 'eclipse'
id 'com.github.johnrengelman.shadow' version '1.1.2'
id 'maven-publish'
}
group = 'shaded.httpcomponents'
version = '4.3.6'
task wrapper(type: Wrapper) { gradleVersion = '2.1' }
task sourceJar(type: Jar, dependsOn: ':shadowSources') {
from files("build/tmp/src")
}
void withFileSystem(URI uri, callback) {
java.nio.file.FileSystem fileSystem = null
try {
fileSystem = java.nio.file.FileSystems.newFileSystem(uri, [:])
callback(fileSystem)
} catch (java.nio.file.FileSystemAlreadyExistsException e) {
fileSystem = java.nio.file.FileSystems.getFileSystem(uri)
callback(fileSystem)
} finally {
if (fileSystem != null) {
fileSystem.close();
}
}
}
task shadowSources << {
String originalPackage = "org.apache"
String originalPath = originalPackage.replace('.', '/')
String shadowedPackage = "shaded"
String shadowedPath = shadowedPackage.replace('.', '/')
java.nio.charset.Charset sourceCharset = java.nio.charset.StandardCharsets.UTF_8
java.nio.file.Path shadowedSourceDir = file("build/tmp/src").toPath()
def componentIds = configurations.compile.incoming.resolutionResult.allDependencies.collect { it.selected.id }
def result = dependencies.createArtifactResolutionQuery()
.forComponents(componentIds)
.withArtifacts(JvmLibrary, SourcesArtifact, JavadocArtifact)
.execute()
for (component in result.resolvedComponents) {
component.getArtifacts(SourcesArtifact).each {
println "Processing sources for ${component.id}: ${it.file}"
int sourceFileCounter = 0
withFileSystem(new URI("jar:file:" + it.file.absolutePath)) { sourceJarFileSystem ->
zipTree(it.file).visit { element ->
String relativePath = element.relativePath.toString()
if (relativePath.startsWith("META-INF") || element.file.isDirectory() ||
!element.file.getName().endsWith(".java")) {
return
}
java.nio.file.Path shadowedFile = shadowedSourceDir.resolve(relativePath.replace(originalPath, shadowedPath))
if (java.nio.file.Files.exists(shadowedFile)) {
return
}
if (!java.nio.file.Files.exists(shadowedFile.getParent())) {
java.nio.file.Files.createDirectories(shadowedFile.getParent())
}
sourceFileCounter++
java.nio.file.Path originalFile = sourceJarFileSystem.getPath(element.relativePath.toString())
String content = new String(java.nio.file.Files.readAllBytes(originalFile), sourceCharset);
content = content.replaceAll(originalPackage, shadowedPackage);
java.nio.file.Files.write(shadowedFile, content.getBytes(sourceCharset));
}
}
println " added ${sourceFileCounter} files"
}
}
}
repositories { mavenCentral(); }
dependencies {
compile('org.apache.httpcomponents:httpcore:4.3.3') { exclude module: 'commons-logging' }
compile('org.apache.httpcomponents:httpclient:' + project.version) { exclude module: 'commons-logging' }
compile('org.apache.httpcomponents:httpmime:' + project.version) { exclude module: 'commons-logging' }
compile('commons-fileupload:commons-fileupload:1.3.1') {
exclude module: 'servlet-api'
exclude module: 'portlet-api'
}
compile('commons-io:commons-io:2.4')
}
shadowJar {
classifier ''
relocate 'org.apache.commons.fileupload', 'shaded.commons.fileupload'
relocate 'org.apache.commons.codec', 'shaded.commons.codec'
relocate 'org.apache.commons.io', 'shaded.commons.io'
relocate 'org.apache.http', 'shaded.http'
exclude '**/*.txt'
exclude '**/*.properties'
exclude '**/pom.xml'
exclude '**/portlet'
exclude '**/servlet'
}
publishing {
publications {
shadow(MavenPublication) {
from components.shadow
artifact sourceJar { classifier "sources" }
}
}
repositories { mavenLocal(); }
}