Skip to content

Commit

Permalink
Fix failed test TestRestSpecAnnotation.
Browse files Browse the repository at this point in the history
Refactor build scripts to export global variables.
Add LICENSE header to build scripts.

RB=108595
R=adubman,jbetz,jwalker,sihde,si-dev
A=jbetz,sihde
  • Loading branch information
Keren Jin committed Nov 30, 2012
1 parent e9e17cb commit 0bedafc
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 55 deletions.
16 changes: 8 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
ext.build_script_dir = "${projectDir.path}/build_script"
project.ext.buildScriptDirPath = "${projectDir.path}/build_script"
project.ext.isDefaultEnvironment = !project.hasProperty('overrideBuildEnvironment')

ext.isDefaultEnvironment = !project.hasProperty('overrideBuildEnvironment')

File getEnvironmentScript()
{
final File env = file(isDefaultEnvironment ? 'defaultEnvironment.gradle' : project.overrideBuildEnvironment)
Expand All @@ -10,8 +9,9 @@ File getEnvironmentScript()
}

apply from: environmentScript
apply from: "${buildScriptDirPath}/configBuildScript.gradle"

ext.externalDependency = [
project.ext.externalDependency = [
'avro': 'org.apache.avro:avro:1.4.0',
'cglib': 'cglib:cglib-nodep:2.2',
'codemodel': 'com.sun.codemodel:codemodel:2.2',
Expand Down Expand Up @@ -42,12 +42,12 @@ ext.externalDependency = [
'zookeeper': 'org.apache.zookeeper:zookeeper:3.3.0'
];

if (!isDefaultEnvironment)
if (!project.ext.isDefaultEnvironment)
{
spec.external.each { overrideDepKey, overrideDepValue ->
if (externalDependency[overrideDepKey] != null)
if (project.ext.externalDependency[overrideDepKey] != null)
{
externalDependency[overrideDepKey] = overrideDepValue
project.ext.externalDependency[overrideDepKey] = overrideDepValue
}
}
}
Expand All @@ -68,7 +68,7 @@ subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'

apply from: "${build_script_dir}/cleanGenerated.gradle"
apply from: "${buildScriptDirPath}/cleanGenerated.gradle"

sourceCompatibility = JavaVersion.VERSION_1_6

Expand Down
23 changes: 19 additions & 4 deletions build_script/avroSchema.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
/*
Copyright (c) 2012 LinkedIn Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

final Configuration dataAvroConfig = project(':data-avro').configurations.default
final Configuration dataConfig = project(':data').configurations.default

project.sourceSets.all { SourceSet sourceSet ->
final inputDataSchemaDirPath = "src${File.separatorChar}${sourceSet.name}${File.separatorChar}pegasus"
final String outputDirPath = "src${File.separatorChar}${sourceSet.name}GeneratedAvroSchema${File.separatorChar}avro"

final FileTree inputDataSchemaFiles = project.fileTree(dir: inputDataSchemaDirPath, includes: ["**${File.separatorChar}*.pdsc"])
if (inputDataSchemaFiles.empty)
{
return;
}

final Task generateAvroSchemaTask = project.task(sourceSet.name + 'GenerateAvroSchema', type: JavaExec) {
final String outputDirPath = rootProject.ext.build.getAvroSchemaOutDirPath(project, sourceSet)
rootProject.ext.build.avroSchemaTasks[sourceSet] = project.task(sourceSet.name + 'GenerateAvroSchema', type: JavaExec) {
main = 'com.linkedin.data.avro.generator.AvroSchemaGenerator'
classpath = dataAvroConfig + dataAvroConfig.allArtifacts.files + dataConfig + dataConfig.allArtifacts.files
args outputDirPath
Expand All @@ -22,5 +37,5 @@ project.sourceSets.all { SourceSet sourceSet ->
}
}

project.tasks[sourceSet.getTaskName('', 'jar')].dependsOn(generateAvroSchemaTask)
project.tasks[sourceSet.getTaskName('', 'jar')].dependsOn(rootProject.ext.build.avroSchemaTasks[sourceSet])
}
27 changes: 20 additions & 7 deletions build_script/cleanGenerated.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
File getGeneratedSourceDir(Project project, SourceSet sourceSet, String genType)
{
return project.file("src${File.separatorChar}${sourceSet.name}Generated${genType}")
}
/*
Copyright (c) 2012 LinkedIn Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

project.sourceSets.all { SourceSet sourceSet ->
final Task cleanGeneratedDirTask = project.task(sourceSet.getTaskName('clean', 'GeneratedDir')) << {
project.delete(getGeneratedSourceDir(project, sourceSet, 'DataTemplate'))
project.delete(getGeneratedSourceDir(project, sourceSet, 'Rest'))
project.delete(getGeneratedSourceDir(project, sourceSet, 'AvroSchema'))
project.delete(project.file(rootProject.ext.build.getDataTemplateOutDirPath(project, sourceSet)).parentFile)
project.delete(project.file(rootProject.ext.build.getAvroSchemaOutDirPath(project, sourceSet)).parentFile)
project.delete(project.file(rootProject.ext.build.getRestModelOutDirPath(project, sourceSet)).parentFile)
project.delete(project.file(rootProject.ext.build.getRestClientOutDirPath(project, sourceSet)).parentFile)
}

// make clean depends on deleting the generated directories
project.tasks.clean.dependsOn(cleanGeneratedDirTask)
}
40 changes: 40 additions & 0 deletions build_script/configBuildScript.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright (c) 2012 LinkedIn Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

String getGeneratedSourceDirName(Project project, SourceSet sourceSet, String genType)
{
return "${project.projectDir.path}${File.separatorChar}src${File.separatorChar}${sourceSet.name}Generated${genType}"
}

project.ext.build = [
'dataTemplateTasks': [:],
'avroSchemaTasks': [:],
'restModelTasks': [:],
'restClientTasks': [:],

'getDataTemplateOutDirPath': { Project project, SourceSet sourceSet ->
return getGeneratedSourceDirName(project, sourceSet, 'dataTemplate') + "${File.separatorChar}java"
},
'getAvroSchemaOutDirPath': { Project project, SourceSet sourceSet ->
return getGeneratedSourceDirName(project, sourceSet, 'AvroSchema') + "${File.separatorChar}avro"
},
'getRestModelOutDirPath': { Project project, SourceSet sourceSet ->
return getGeneratedSourceDirName(project, sourceSet, 'Rest') + "${File.separatorChar}idl"
},
'getRestClientOutDirPath': { Project project, SourceSet sourceSet ->
return getGeneratedSourceDirName(project, sourceSet, 'Rest') + "${File.separatorChar}java"
}
]
23 changes: 19 additions & 4 deletions build_script/dataTemplate.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
/*
Copyright (c) 2012 LinkedIn Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

final Configuration generatorConfig = project(':generator').configurations.default

project.sourceSets.all { SourceSet sourceSet ->
final inputDataSchemaDirPath = "src${File.separatorChar}${sourceSet.name}${File.separatorChar}pegasus"
final String outputDirPath = "src${File.separatorChar}${sourceSet.name}GeneratedDataTemplate${File.separatorChar}java"

final FileTree inputDataSchemaFiles = project.fileTree(dir: inputDataSchemaDirPath, includes: ["**${File.separatorChar}*.pdsc"])
if (inputDataSchemaFiles.empty)
{
return;
}

final String outputDirPath = rootProject.ext.build.getDataTemplateOutDirPath(project, sourceSet)
sourceSet.java.srcDir(outputDirPath)

final Task generateDataTemplateTask = project.task(sourceSet.name + 'GenerateDataTemplate', type: JavaExec) {
rootProject.ext.build.dataTemplateTasks[sourceSet] = project.task(sourceSet.name + 'GenerateDataTemplate', type: JavaExec) {
main = 'com.linkedin.pegasus.generator.PegasusDataTemplateGenerator'
classpath = generatorConfig + generatorConfig.allArtifacts.files
args outputDirPath
Expand All @@ -23,5 +38,5 @@ project.sourceSets.all { SourceSet sourceSet ->
}
}

project.tasks[sourceSet.compileJavaTaskName].dependsOn(generateDataTemplateTask)
project.tasks[sourceSet.compileJavaTaskName].dependsOn(rootProject.ext.build.dataTemplateTasks[sourceSet])
}
23 changes: 19 additions & 4 deletions build_script/publishIdl.gradle
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
/*
Copyright (c) 2012 LinkedIn Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

final Configuration restliToolsConfig = project(':restli-tools').configurations.default
final String IDL_COMPAT_REQUIREMENT_NAME = 'rest.model.compatibility'

project.sourceSets.all { SourceSet sourceSet ->
// test resources and .restspec.json files are not meant to be published
if (sourceSet == project.sourceSets.test)
{
return
}

final String currIdlDirPath = "src${File.separatorChar}${sourceSet.name}GeneratedRest${File.separatorChar}idl"
final String apiIdlDirRelativePath = "src${File.separatorChar}${sourceSet.name}${File.separatorChar}idl"
final String dataSchemaRelativePath = "src${File.separatorChar}${sourceSet.name}${File.separatorChar}pegasus"

final FileTree currIdlFiles = project.fileTree(dir: currIdlDirPath, includes: ["**${File.separatorChar}*.restspec.json"])
if (currIdlFiles.empty)
{
return;
}

final String apiIdlDirRelativePath = "src${File.separatorChar}${sourceSet.name}${File.separatorChar}idl"
final String dataSchemaRelativePath = "src${File.separatorChar}${sourceSet.name}${File.separatorChar}pegasus"
final File apiIdlDir = apiProject.file(apiIdlDirRelativePath)
final String compatLevel = (project.hasProperty(IDL_COMPAT_REQUIREMENT_NAME) ? project.property(IDL_COMPAT_REQUIREMENT_NAME)
: 'equivalent')

final Task checkIdlTask = project.task(sourceSet.name + 'CheckIdl',
type: JavaExec,
dependsOn: project.tasks[sourceSet.name + 'GenerateRestModel']) {
Expand Down
23 changes: 19 additions & 4 deletions build_script/restClient.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
/*
Copyright (c) 2012 LinkedIn Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

final Configuration restliToolsConfig = project(':restli-tools').configurations.default

project.sourceSets.all { SourceSet sourceSet ->
final inputIdlDirPath = "src${File.separatorChar}${sourceSet.name}${File.separatorChar}idl"
final String outputDirPath = "src${File.separatorChar}${sourceSet.name}GeneratedRest${File.separatorChar}java"

final FileTree inputIdlFiles = project.fileTree(dir: inputIdlDirPath, includes: ["**${File.separatorChar}*.restspec.json"])
if (inputIdlFiles.empty)
{
return;
}

final String outputDirPath = rootProject.ext.build.getRestClientOutDirPath(project, sourceSet)
sourceSet.java.srcDir(outputDirPath)

final Task generateRestClientTask = project.task(sourceSet.name + 'GenerateRestClient', type: JavaExec) {
rootProject.ext.build.restClientTasks[sourceSet] = project.task(sourceSet.name + 'GenerateRestClient', type: JavaExec) {
main = 'com.linkedin.restli.tools.clientgen.RestRequestBuilderGenerator'
classpath = restliToolsConfig + restliToolsConfig.allArtifacts.files
args outputDirPath
Expand All @@ -24,5 +39,5 @@ project.sourceSets.all { SourceSet sourceSet ->
}
}

project.tasks[sourceSet.compileJavaTaskName].dependsOn(generateRestClientTask)
project.tasks[sourceSet.compileJavaTaskName].dependsOn(rootProject.ext.build.restClientTasks[sourceSet])
}
32 changes: 24 additions & 8 deletions build_script/restModel.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
/*
Copyright (c) 2012 LinkedIn Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

final Configuration restliToolsConfig = project(':restli-tools').configurations.default

project.sourceSets.all { SourceSet sourceSet ->
if (project.ext.resourcePackages[sourceSet.name] == null ||
project.ext.resourcePackages[sourceSet.name].empty)
if (project.ext.resourcePackages[sourceSet.name] == null || project.ext.resourcePackages[sourceSet.name].empty)
{
return;
}

final String outputDirPath = "src${File.separatorChar}${sourceSet.name}GeneratedRest${File.separatorChar}idl"

final Task generateRestModelTask = project.task(sourceSet.name + 'GenerateRestModel',
type: JavaExec,
dependsOn: tasks[sourceSet.classesTaskName]) {
final String outputDirPath = rootProject.ext.build.getRestModelOutDirPath(project, sourceSet)
rootProject.ext.build.restModelTasks[sourceSet] = project.task(sourceSet.name + 'GenerateRestModel',
type: JavaExec,
dependsOn: tasks[sourceSet.classesTaskName]) {
main = 'com.linkedin.restli.tools.idlgen.RestLiResourceModelExporterCmdLineApp'
classpath = restliToolsConfig + restliToolsConfig.allArtifacts.files + sourceSet.compileClasspath + project.files(sourceSet.output.classesDir)
args '-outdir'
Expand All @@ -25,5 +39,7 @@ project.sourceSets.all { SourceSet sourceSet ->
}
}

project.tasks[sourceSet.getTaskName('', 'jar')].dependsOn(generateRestModelTask)
// .restspec.json file generation requires class files be generated first
// make jar task, which always runs after class generation, depend on this task
project.tasks[sourceSet.getTaskName('', 'jar')].dependsOn(rootProject.ext.build.restModelTasks[sourceSet])
}
4 changes: 2 additions & 2 deletions generator-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ dependencies {
project.sourceSets.test.java.srcDir('src/test/javaPegasus')
project.idea.module.testSourceDirs.add('src/test/javaPegasus')

apply from: "${build_script_dir}/dataTemplate.gradle"
apply from: "${build_script_dir}/avroSchema.gradle"
apply from: "${buildScriptDirPath}/dataTemplate.gradle"
apply from: "${buildScriptDirPath}/avroSchema.gradle"
2 changes: 1 addition & 1 deletion restli-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
testRuntime externalDependency.cglib
}

apply from: "${build_script_dir}/dataTemplate.gradle"
apply from: "${buildScriptDirPath}/dataTemplate.gradle"

test {
systemProperties['test.projectDir'] = projectDir.toString()
Expand Down
2 changes: 1 addition & 1 deletion restli-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ dependencies {
testCompile externalDependency.testng
}

apply from: "${build_script_dir}/dataTemplate.gradle"
apply from: "${buildScriptDirPath}/dataTemplate.gradle"
4 changes: 2 additions & 2 deletions restli-example-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ dependencies {
compile project(':restli-client')
}

apply from: "${build_script_dir}/dataTemplate.gradle"
apply from: "${build_script_dir}/restClient.gradle"
apply from: "${buildScriptDirPath}/dataTemplate.gradle"
apply from: "${buildScriptDirPath}/restClient.gradle"
Loading

0 comments on commit 0bedafc

Please sign in to comment.