Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
build: remove obsolete plugin and migrate Eclipse setup (#1545)
Browse files Browse the repository at this point in the history
* build: remove obsolete plugin and migrate
* clean up
  • Loading branch information
chanseokoh committed Oct 20, 2021
1 parent 9f96d14 commit 9ab6bbf
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tmp_docs
bazel-*

# Eclipse
.apt_generated
.apt_generated*
.classpath
.factorypath
.project
Expand Down
169 changes: 52 additions & 117 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,44 @@ plugins {
id 'java'
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'

id 'com.diffplug.eclipse.apt' version '3.33.1' apply false
id 'com.dorongold.task-tree' version '2.1.0' apply false
id 'com.github.johnrengelman.shadow' version '6.1.0' apply false
id 'com.github.sherter.google-java-format' version '0.8' apply false
id 'net.ltgt.apt' version '0.21' apply false
}

// TODO: Populate this from dependencies.properties version property (for proper Gradle-Bazel sync)
project.version = "2.6.1-SNAPSHOT" // {x-version-update:gax:current}

allprojects {
group = 'com.google.api'
}

// Project names not used for release
def nonReleaseProjects = ['benchmark']
// Project names not using the default publication configuration
def noDefaultPublications = ['benchmark', 'gax-bom']
def nonJavaProjects = ['gax-bom']

ext.libraryVendor = 'Google'

allprojects {
group = 'com.google.api'
ext {
libraryVendor = 'Google'

// Load Dependencies shared between Bazel and Gradle build scripts
libraries = new Properties()
file('dependencies.properties').withReader { libraries.load(it) }
// Gradle-specific build script dependencies
libraries.putAll(
'maven.io_grpc_grpc_bom': "io.grpc:grpc-bom:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_core': "io.grpc:grpc-core:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_context': "io.grpc:grpc-context:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_stub': "io.grpc:grpc-stub:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_api': "io.grpc:grpc-api:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_auth': "io.grpc:grpc-auth:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_protobuf': "io.grpc:grpc-protobuf:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_netty_shaded': "io.grpc:grpc-netty-shaded:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_alts': "io.grpc:grpc-alts:${libraries['version.io_grpc']}",
'maven.com_google_protobuf': "com.google.protobuf:protobuf-java:${libraries['version.com_google_protobuf']}",
'maven.com_google_protobuf_java_util': "com.google.protobuf:protobuf-java-util:${libraries['version.com_google_protobuf']}")
}

nexusPublishing {
Expand All @@ -44,79 +63,51 @@ configure(javaProjects) {
apply plugin: 'idea'
apply plugin: 'jacoco'

apply plugin: 'com.diffplug.eclipse.apt'
apply plugin: 'com.dorongold.task-tree'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'com.github.sherter.google-java-format'
apply plugin: 'net.ltgt.apt'

sourceCompatibility = 1.8
targetCompatibility = 1.8

// Formatting tasks
// ================
googleJavaFormat {
exclude '.apt_generated/**'
exclude '.apt_generated*/**'
exclude 'bin/**'
exclude 'build/**'
exclude 'bazel*/**'
}

test.dependsOn verifyGoogleJavaFormat

task verifyLicense {
doLast {
def licenseText = new File(rootProject.rootDir, 'license-header-javadoc.txt').text
def licenseText = new File('license-header-javadoc.txt').text
def srcFiles = []
sourceSets
.collectMany{it.allJava.getSrcDirs()}
.grep{it.exists()}
.each{it.eachFileRecurse(FileType.FILES, {srcFiles << new Tuple(it, it.text)})}
srcFiles = srcFiles
.findAll{it.get(0).path.endsWith(".java")}
.collect{new Tuple(it.get(0), it.get(1).replaceAll("Copyright 20[0-9]{2}", "Copyright 20xx"))}
.findAll{it.get(0).path.endsWith('.java')}
.collect{new Tuple(it.get(0), it.get(1).replaceAll('Copyright 20[0-9]{2}', 'Copyright 20xx'))}
.findAll{!it.get(1).startsWith(licenseText)}
if (srcFiles.asList().size() > 0) {
srcFiles.each({println 'missing license: ' + it.get(0)})
throw new IllegalStateException("Above files do not have licenses")
throw new IllegalStateException('Above files do not have licenses')
}
}
}
test.dependsOn verifyLicense

gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation'
}

// Dependencies
// ------------

jacoco {
toolVersion = "0.8.5"
}

ext {
// Load Dependencies shared between Bazel and Gradle build scripts
libraries = new Properties()
file(new File(rootDir, "dependencies.properties")).withReader{ libraries.load((Reader) it) }

// Gradle-specific build script dependencies
libraries.putAll([
'maven.io_grpc_grpc_bom': "io.grpc:grpc-bom:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_core': "io.grpc:grpc-core:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_context': "io.grpc:grpc-context:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_stub': "io.grpc:grpc-stub:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_api': "io.grpc:grpc-api:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_auth': "io.grpc:grpc-auth:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_protobuf': "io.grpc:grpc-protobuf:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_netty_shaded': "io.grpc:grpc-netty-shaded:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_alts': "io.grpc:grpc-alts:${libraries['version.io_grpc']}",
'maven.com_google_protobuf': "com.google.protobuf:protobuf-java:${libraries['version.com_google_protobuf']}",
'maven.com_google_protobuf_java_util': "com.google.protobuf:protobuf-java-util:${libraries['version.com_google_protobuf']}"
])
}

repositories {
mavenLocal()
mavenCentral()
Expand All @@ -125,21 +116,26 @@ configure(javaProjects) {
configurations {
shadowNoGuava
linkageChecker
implementation.exclude group: 'com.google.guava', module: 'guava-jdk5'
}

dependencies {
// Separate configuration (class path) for Linkage Checker
linkageChecker 'com.google.cloud.tools:dependencies:1.5.12'
}

jacoco.toolVersion = '0.8.5'
jacocoTestReport {
reports {
xml.enabled true
html.enabled true
}
afterEvaluate {
getClassDirectories().setFrom files(classDirectories.files.collect {
fileTree(dir: it,
exclude: ['**/AutoValue_*'])
})
fileTree(dir: it, exclude: ['**/AutoValue_*'])
})
}
}

check.dependsOn jacocoTestReport


Expand Down Expand Up @@ -211,74 +207,13 @@ configure(javaProjects) {

test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
exceptionFormat = 'full'
}
}


// Eclipse Annotation Processing
// -----------------------------

ext {
eclipseAptFolder = '.apt_generated'
eclipseSettingsDir = file('.settings')
}

configurations {
codeGeneration
implementation.exclude group: 'com.google.guava', module: 'guava-jdk5'
}

dependencies {
codeGeneration (libraries['maven.com_google_auto_value_auto_value'],
libraries['maven.com_google_code_findbugs_jsr305'])

// Separate configuration (class path) for Linkage Checker
linkageChecker "com.google.cloud.tools:dependencies:1.5.12"
}

compileJava.classpath += configurations.codeGeneration

eclipse {
jdt.file.withProperties {
it['org.eclipse.jdt.core.compiler.processAnnotations'] = 'enabled'
}
}

tasks.eclipseJdt {
doFirst {
def aptPrefs =
file("${eclipseSettingsDir}/org.eclipse.jdt.apt.core.prefs")
aptPrefs.parentFile.mkdirs()

aptPrefs.text = """\
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=${eclipseAptFolder}
org.eclipse.jdt.apt.reconcileEnabled=true
""".stripIndent()

file('.factorypath').withWriter {
new groovy.xml.MarkupBuilder(it).'factorypath' {
project.configurations.codeGeneration.each { dep->
factorypathentry(
kind:'EXTJAR',
id:dep.absolutePath,
enabled:true,
runInBatchMode:false)
}
}
}
}
}

tasks.cleanEclipseJdt {
doFirst {
delete file("${eclipseSettingsDir}/org.eclipse.jdt.apt.core.prefs"),
file('.factorypath')
}
}
// Eclipse annotation processing auto-setup
eclipse.synchronizationTasks eclipseJdtApt, eclipseJdt, eclipseFactorypath
}

def normalReleasableProjects = subprojects.findAll {
Expand Down Expand Up @@ -379,20 +314,20 @@ javadoc.options {
task javadocCombined(type: Javadoc) {
source subprojects.collect {project -> project.sourceSets.main.allJava }
classpath = files(subprojects.collect {project -> project.sourceSets.main.compileClasspath})
destinationDir = new File(projectDir, 'tmp_docs')
destinationDir = file('tmp_docs')
}

// JavaDocV3 docFX
// -------
task javadocCombinedV3(type: Javadoc) {
source subprojects.collect {project -> project.sourceSets.main.allJava }
classpath = files(subprojects.collect {project -> project.sourceSets.main.compileClasspath})
destinationDir = new File(projectDir, 'tmp_docs/docfx-yml')
destinationDir = file('tmp_docs/docfx-yml')

options.addStringOption('encoding', 'UTF-8')
options.addStringOption("doclet", "com.microsoft.doclet.DocFxDoclet")
options.addStringOption("projectname", "gax")
options.docletpath = [file(System.getenv('KOKORO_GFILE_DIR') + "/java-docfx-doclet-1.3.0.jar")]
options.addStringOption('doclet', 'com.microsoft.doclet.DocFxDoclet')
options.addStringOption('projectname', 'gax')
options.docletpath = [file(System.getenv('KOKORO_GFILE_DIR') + '/java-docfx-doclet-1.3.0.jar')]
// Newer Gradle 6 passes -notimestamp by default, which the doclet above doesn't understand:
// https://github.com/gradle/gradle/issues/11898
options.noTimestamp false
Expand Down Expand Up @@ -487,7 +422,7 @@ task stageRelease {
// 3. Remove tmp_gh-pages
// Note: This task assumes that the 'stage_release' task has been completed.
task finalizeRelease {
dependsOn 'publishDocs'
dependsOn publishDocs
doLast {
exec {
commandLine 'rm', '-r', 'tmp_gh-pages'
Expand All @@ -500,9 +435,9 @@ task finalizeRelease {
// https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/Linkage-Monitor#linkage-monitor-artifactstxt
task createLinkageMonitorArtifactList {
doLast {
def httpJsonVersion = project(":gax-httpjson").version
def httpJsonVersion = project(':gax-httpjson').version

new File(projectDir, "linkage-monitor-artifacts.txt").text = """
new File('linkage-monitor-artifacts.txt').text = """
com.google.api:gax:$version
com.google.api:gax-grpc:$version
com.google.api:gax-httpjson:$httpJsonVersion
Expand Down
2 changes: 1 addition & 1 deletion gax-grpc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
archivesBaseName = "gax-grpc"
archivesBaseName = 'gax-grpc'

// TODO: Populate this from dependencies.properties version property (for proper Gradle-Bazel sync)
project.version = "2.6.1-SNAPSHOT" // {x-version-update:gax-grpc:current}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public void testWithGCECredentials() throws IOException {

ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator =
new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
@Override
public ManagedChannelBuilder apply(ManagedChannelBuilder channelBuilder) {
if (InstantiatingGrpcChannelProvider.isOnComputeEngine()) {
assertThat(channelBuilder instanceof ComputeEngineChannelBuilder).isTrue();
Expand Down Expand Up @@ -304,6 +305,7 @@ public void testWithNonGCECredentials() throws IOException {

ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator =
new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
@Override
public ManagedChannelBuilder apply(ManagedChannelBuilder channelBuilder) {
// Clients with non-GCE credentials will not attempt DirectPath.
assertThat(channelBuilder instanceof ComputeEngineChannelBuilder).isFalse();
Expand Down Expand Up @@ -334,6 +336,7 @@ public void testWithDirectPathDisabled() throws IOException {

ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator =
new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
@Override
public ManagedChannelBuilder apply(ManagedChannelBuilder channelBuilder) {
// Clients without setting attemptDirectPath flag will not attempt DirectPath
assertThat(channelBuilder instanceof ComputeEngineChannelBuilder).isFalse();
Expand Down Expand Up @@ -364,6 +367,7 @@ public void testWithNoDirectPathFlagSet() throws IOException {

ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator =
new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
@Override
public ManagedChannelBuilder apply(ManagedChannelBuilder channelBuilder) {
// Clients without setting attemptDirectPath flag will not attempt DirectPath
assertThat(channelBuilder instanceof ComputeEngineChannelBuilder).isFalse();
Expand Down
2 changes: 1 addition & 1 deletion gax-httpjson/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
archivesBaseName = "gax-httpjson"
archivesBaseName = 'gax-httpjson'

// TODO: Populate this from dependencies.properties version property (for proper Gradle-Bazel sync)
project.version = "0.91.1-SNAPSHOT" // {x-version-update:gax-httpjson:current}
Expand Down

0 comments on commit 9ab6bbf

Please sign in to comment.