Skip to content

Commit 801b587

Browse files
committed
ScmPlugin: Try to generate buildMetaData.json even when scmPlugin is disabled
People seem to disable scm plugin to improve their zip size/performance. Changed the flag to two flags to allow metadata.json to be created by default but for projects where existing flags is set to false, the zip will not be created
1 parent 03e6e0d commit 801b587

File tree

2 files changed

+143
-68
lines changed

2 files changed

+143
-68
lines changed

hadoop-plugin/src/main/groovy/com/linkedin/gradle/scm/ScmPlugin.groovy

+16-14
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,17 @@ import org.gradle.api.tasks.bundling.Zip
2727
import java.nio.file.Path
2828
import java.nio.file.Paths;
2929

30+
3031
/**
3132
* ScmPlugin implements features that generate source control management (scm) metadata, in
32-
* particular for Git and Subversion.
33-
*/
33+
* particular for Git and Subversion.*/
3434
class ScmPlugin implements Plugin<Project> {
35-
/**
36-
* Applies the ScmPlugin.
37-
*
38-
* @param project The Gradle project
39-
*/
40-
@Override
41-
void apply(Project project) {
42-
// Enable users to skip the plugin
43-
if (project.hasProperty("disableScmPlugin")) {
44-
println("ScmPlugin disabled");
45-
return;
46-
}
4735

36+
void applyMetadataTasks(Project project) {
37+
if (project.hasProperty("disableScmPluginMetaData")) {
38+
println("ScmPlugin buildMetadata.json disabled")
39+
return
40+
}
4841
project.tasks.create("buildScmMetadata") {
4942
description = "Writes SCM metadata about the project to the project's build directory";
5043
group = "Hadoop Plugin";
@@ -83,7 +76,16 @@ class ScmPlugin implements Plugin<Project> {
8376
}
8477
}
8578
}
79+
}
8680

81+
@Override
82+
void apply(Project project) {
83+
applyMetadataTasks(project)
84+
// Allows users to skip the plugin if they don't want the sources zip (performance improvement)
85+
if (project.hasProperty("disableScmPlugin")) {
86+
println("ScmPlugin's sources.zip is disabled");
87+
return;
88+
}
8789
// We'll create the buildSourceZip task on the root project, so that there is only one sources
8890
// zip created that can be shared by all projects. Thus, only create the buildSourceZip task on
8991
// the root project if it hasn't been created already (you will get an exception if you try to

li-hadoop-plugin/src/integTest/groovy/com/linkedin/gradle/BuildHadoopZips.groovy

+127-54
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,131 @@ import java.util.zip.ZipFile
1212

1313
class BuildHadoopZips extends Specification {
1414

15-
@Rule
16-
TemporaryFolder tmp = new TemporaryFolder()
17-
18-
def buildDotGradle
19-
def settingsDotGradle
20-
def gradleDotProperties
21-
def dotCrt
22-
23-
def setup() {
24-
tmp.create()
25-
buildDotGradle = tmp.newFile('build.gradle')
26-
settingsDotGradle = tmp.newFile('settings.gradle')
27-
gradleDotProperties = tmp.newFile('gradle.properties')
28-
dotCrt = tmp.newFile('.crt')
29-
}
30-
31-
/**
32-
* Integration test for including the sources zip and SCM metadata file in the Hadoop zip
33-
*/
34-
def 'verify zip contents'() {
35-
given:
36-
def projectName = 'build-hadoop-zips'
37-
def version = '1.0.0'
38-
buildDotGradle << this.class.classLoader.getResource('buildZips/buildZipsCRT.gradle').text
39-
settingsDotGradle << """rootProject.name='${projectName}'"""
40-
gradleDotProperties << """version=${version}"""
41-
dotCrt << '''Test .crt file\n'''
42-
GradleRunner runner = GradleRunner.create()
43-
.withProjectDir(tmp.root)
44-
.withPluginClasspath()
45-
.withArguments('buildHadoopZips', '-is')
46-
47-
when:
48-
BuildResult result = runner.build()
49-
50-
then:
51-
result.task(':azkabanHadoopZip').outcome == TaskOutcome.SUCCESS
52-
result.task(':CRTHadoopZip').outcome == TaskOutcome.SUCCESS
53-
54-
// find CRTHadoopZip, assert contains .crt file (build/distributions/build-hadoop-zips-1.0.0.zip)
55-
def crtHadoopZip = new File(tmp.root, "build/distributions/${projectName}-${version}.zip")
56-
crtHadoopZip.exists()
57-
def crtHadoopZipContents = new ZipFile(crtHadoopZip)
58-
assert crtHadoopZipContents.getEntry('.crt') != null
59-
60-
// find azkabanHadoopZip, assert contents (build/distributions/build-hadoop-zips-1.0.0-azkaban.zip)
61-
// contents == build.gradle, buildMetadata.json, build-hadoop-zips-1.0.0-sources.zip
62-
def azkabanZip = new File(tmp.root, "build/distributions/${projectName}-${version}-azkaban.zip")
63-
azkabanZip.exists()
64-
def zipFileContents = new ZipFile(azkabanZip)
65-
zipFileContents.getEntry('build.gradle') != null
66-
zipFileContents.getEntry('buildMetadata.json') != null
67-
zipFileContents.getEntry("${projectName}-${version}-sources.zip") != null
68-
}
15+
@Rule
16+
TemporaryFolder tmp = new TemporaryFolder()
17+
18+
def buildDotGradle
19+
def settingsDotGradle
20+
def gradleDotProperties
21+
def dotCrt
22+
23+
def setup() {
24+
tmp.create()
25+
buildDotGradle = tmp.newFile('build.gradle')
26+
settingsDotGradle = tmp.newFile('settings.gradle')
27+
gradleDotProperties = tmp.newFile('gradle.properties')
28+
dotCrt = tmp.newFile('.crt')
29+
}
30+
31+
/**
32+
* Integration test for including the sources zip and SCM metadata file in the Hadoop zip*/
33+
def 'verify zip contents'() {
34+
given:
35+
def projectName = 'build-hadoop-zips'
36+
def version = '1.0.0'
37+
buildDotGradle << this.class.classLoader.getResource('buildZips/buildZipsCRT.gradle').text
38+
settingsDotGradle << """rootProject.name='${projectName}'"""
39+
gradleDotProperties << """version=${version}"""
40+
dotCrt << '''Test .crt file\n'''
41+
GradleRunner runner = GradleRunner.create()
42+
.withProjectDir(tmp.root)
43+
.withPluginClasspath()
44+
.withArguments('buildHadoopZips', '-is')
45+
46+
when:
47+
BuildResult result = runner.build()
48+
49+
then:
50+
result.task(':azkabanHadoopZip').outcome == TaskOutcome.SUCCESS
51+
result.task(':CRTHadoopZip').outcome == TaskOutcome.SUCCESS
52+
53+
// find CRTHadoopZip, assert contains .crt file (build/distributions/build-hadoop-zips-1.0.0.zip)
54+
def crtHadoopZip = new File(tmp.root, "build/distributions/${projectName}-${version}.zip")
55+
crtHadoopZip.exists()
56+
def crtHadoopZipContents = new ZipFile(crtHadoopZip)
57+
assert crtHadoopZipContents.getEntry('.crt') != null
58+
59+
// find azkabanHadoopZip, assert contents (build/distributions/build-hadoop-zips-1.0.0-azkaban.zip)
60+
// contents == build.gradle, buildMetadata.json, build-hadoop-zips-1.0.0-sources.zip
61+
def azkabanZip = new File(tmp.root, "build/distributions/${projectName}-${version}-azkaban.zip")
62+
azkabanZip.exists()
63+
def zipFileContents = new ZipFile(azkabanZip)
64+
zipFileContents.getEntry('build.gradle') != null
65+
zipFileContents.getEntry('buildMetadata.json') != null
66+
zipFileContents.getEntry("${projectName}-${version}-sources.zip") != null
67+
}
68+
69+
def 'verify zip contents doesnt include buildMetadata when asked'() {
70+
given:
71+
def projectName = 'build-hadoop-zips'
72+
def version = '1.0.0'
73+
buildDotGradle << this.class.classLoader.getResource('buildZips/buildZipsCRT.gradle').text
74+
settingsDotGradle << """rootProject.name='${projectName}'"""
75+
gradleDotProperties << """version=${version}\ndisableScmPluginMetaData=true\n"""
76+
dotCrt << '''Test .crt file\n'''
77+
GradleRunner runner = GradleRunner.create()
78+
.withProjectDir(tmp.root)
79+
.withPluginClasspath()
80+
.withArguments('buildHadoopZips', '-is')
81+
.forwardOutput()
82+
.withDebug(true)
83+
84+
when:
85+
BuildResult result = runner.build()
86+
87+
then:
88+
result.task(':azkabanHadoopZip').outcome == TaskOutcome.SUCCESS
89+
result.task(':CRTHadoopZip').outcome == TaskOutcome.SUCCESS
90+
91+
// find CRTHadoopZip, assert contains .crt file (build/distributions/build-hadoop-zips-1.0.0.zip)
92+
def crtHadoopZip = new File(tmp.root, "build/distributions/${projectName}-${version}.zip")
93+
crtHadoopZip.exists()
94+
def crtHadoopZipContents = new ZipFile(crtHadoopZip)
95+
assert crtHadoopZipContents.getEntry('.crt') != null
96+
97+
// find azkabanHadoopZip, assert contents (build/distributions/build-hadoop-zips-1.0.0-azkaban.zip)
98+
// contents == build.gradle, buildMetadata.json, build-hadoop-zips-1.0.0-sources.zip
99+
def azkabanZip = new File(tmp.root, "build/distributions/${projectName}-${version}-azkaban.zip")
100+
azkabanZip.exists()
101+
def zipFileContents = new ZipFile(azkabanZip)
102+
zipFileContents.getEntry('build.gradle') != null
103+
zipFileContents.getEntry('buildMetadata.json') == null
104+
zipFileContents.getEntry("${projectName}-${version}-sources.zip") != null
105+
}
106+
107+
def 'verify zip contents doesnt include buildMetadata AND sources when asked'() {
108+
given:
109+
def projectName = 'build-hadoop-zips'
110+
def version = '1.0.0'
111+
buildDotGradle << this.class.classLoader.getResource('buildZips/buildZipsCRT.gradle').text
112+
settingsDotGradle << """rootProject.name='${projectName}'"""
113+
gradleDotProperties << """version=${version}\ndisableScmPluginMetaData=true\ndisableScmPlugin=true"""
114+
dotCrt << '''Test .crt file\n'''
115+
GradleRunner runner = GradleRunner.create()
116+
.withProjectDir(tmp.root)
117+
.withPluginClasspath()
118+
.withArguments('buildHadoopZips', '-is')
119+
120+
when:
121+
BuildResult result = runner.build()
122+
123+
then:
124+
result.task(':azkabanHadoopZip').outcome == TaskOutcome.SUCCESS
125+
result.task(':CRTHadoopZip').outcome == TaskOutcome.SUCCESS
126+
127+
// find CRTHadoopZip, assert contains .crt file (build/distributions/build-hadoop-zips-1.0.0.zip)
128+
def crtHadoopZip = new File(tmp.root, "build/distributions/${projectName}-${version}.zip")
129+
crtHadoopZip.exists()
130+
def crtHadoopZipContents = new ZipFile(crtHadoopZip)
131+
assert crtHadoopZipContents.getEntry('.crt') != null
132+
133+
// find azkabanHadoopZip, assert contents (build/distributions/build-hadoop-zips-1.0.0-azkaban.zip)
134+
// contents == build.gradle, buildMetadata.json, build-hadoop-zips-1.0.0-sources.zip
135+
def azkabanZip = new File(tmp.root, "build/distributions/${projectName}-${version}-azkaban.zip")
136+
azkabanZip.exists()
137+
def zipFileContents = new ZipFile(azkabanZip)
138+
zipFileContents.getEntry('build.gradle') != null
139+
zipFileContents.getEntry('buildMetadata.json') == null
140+
zipFileContents.getEntry("${projectName}-${version}-sources.zip") == null
141+
}
69142
}

0 commit comments

Comments
 (0)